{"record":{"id":"8dc6c4137de447d7","repo":"hashicorp/terraform","slug":"failed-to-initialize-config-loader-s-8dc6c4","errorCode":null,"errorMessage":"Failed to initialize config loader: %s","messagePattern":"Failed to initialize config loader: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/query.go","lineNumber":205,"sourceCode":"\tgenerateConfigOut string,\n\tpolicyPaths []string,\n) (*backendrun.Operation, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\t// Build the operation\n\topReq := c.Operation(be, viewType)\n\topReq.Hooks = view.Hooks()\n\topReq.ConfigDir = \".\"\n\topReq.Type = backendrun.OperationTypePlan\n\topReq.GenerateConfigOut = generateConfigOut\n\topReq.View = view.Operation()\n\topReq.Query = true\n\topReq.PolicyPaths = policyPaths\n\n\tvar err error\n\topReq.ConfigLoader, err = c.initConfigLoader()\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to initialize config loader: %s\", err))\n\t\treturn nil, diags\n\t}\n\n\treturn opReq, diags\n}\n","sourceCodeStart":187,"sourceCodeEnd":211,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/query.go#L187-L211","documentation":"QueryCommand opReq construction calls c.initConfigLoader(); on failure the error is wrapped and the query operation request cannot be built. Identical pattern to plan/refresh but on the query command path. The loader is responsible for parsing config and preparing module installation state.","triggerScenarios":"terraform query (the query/plan-with-policy command) is invoked; c.initConfigLoader() returns err — config parse failures, missing config dir, or module installer state issues.","commonSituations":"Running query with unparseable .tf files; outside the config dir; after a backend or module change without terraform init; missing files referenced by the configuration.","solutions":["Run terraform validate / terraform fmt to catch HCL errors.","Run terraform init to prepare the loader and modules.","Run from the config root or use -chdir.","Inspect the wrapped %s for the precise parse/load failure."],"exampleFix":"# before: query fails on loader init\nterraform query\n# after\nterraform init\nterraform validate\nterraform query","handlingStrategy":"validation","validationCode":"// Pre-check config loads before the query command.\nif _, err := c.initConfigLoader(); err != nil {\n    return fmt.Errorf(\"config loader failed; run 'terraform init' and 'terraform validate': %w\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run terraform validate before query.","Keep terraform init current.","Invoke from the configuration root or use -chdir."],"tags":["terraform","config-loader","query","config-parse","cli"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}