{"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":"console","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/query.go#L187-L211","documentation":"Wrapped error from QueryCommand.operation when c.initConfigLoader() fails. The query command (experimental, runs a speculative plan-like evaluation) needs the config loader to parse configuration and query files before executing. Failure aborts before the operation is built. %s embeds the NewLoader error.","triggerScenarios":"Running 'terraform query' (experimental) when configload.NewLoader errors — invalid CLI config, inaccessible modules directory, or services init failure. Same root causes as the plan/refresh loader errors.","commonSituations":"Same as 727/730: bad TF_CLI_CONFIG_FILE, read-only data directory, network/proxy blocking services discovery, container filesystem restrictions.","solutions":["Inspect the embedded error for the specific loader failure.","Validate/repair TF_CLI_CONFIG_FILE and ~/.terraformrc.","Ensure the data directory and working directory are writable.","Use TF_LOG=trace to locate the failing init step."],"exampleFix":"// before\n$ terraform query\nFailed to initialize config loader: ...\n// after\n$ unset TF_CLI_CONFIG_FILE\n$ terraform init && terraform query","handlingStrategy":"validation","validationCode":"// Reuse the same preflight as plan: ensure CLI config + data dir are usable\npackage main\n\nfunc preflightConfigLoader(cliConfig, dataDir string) error {\n\tif cliConfig != \"\" {\n\t\tif _, err := os.ReadFile(cliConfig); err != nil {\n\t\t\treturn fmt.Errorf(\"TF_CLI_CONFIG_FILE unreadable: %w\", err)\n\t\t}\n\t}\n\tif err := os.MkdirAll(dataDir, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"data dir not writable: %w\", err)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'terraform init' before the experimental query command.","Keep CLI config valid and data directory writable.","Treat query as experimental; verify against a known-good checkout first."],"tags":["config-loader","query","cli-config","initialization","experimental"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}