{"record":{"id":"5ace502b255bb33e","repo":"hashicorp/terraform","slug":"failed-to-initialize-config-loader-s-5ace50","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/plan.go","lineNumber":190,"sourceCode":"\n\t// EXPERIMENTAL: maybe enable deferred actions\n\tif c.AllowExperimentalFeatures {\n\t\topReq.DeferralAllowed = args.DeferralAllowed\n\t} else if args.DeferralAllowed {\n\t\t// Belated flag parse error, since we don't know about experiments\n\t\t// support at actual parse time.\n\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\ttfdiags.Error,\n\t\t\t\"Failed to parse command-line flags\",\n\t\t\t\"The -allow-deferral flag is only valid in experimental builds of Terraform.\",\n\t\t))\n\t\treturn nil, diags\n\t}\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\nfunc (c *PlanCommand) Help() string {\n\thelpText := `\nUsage: terraform [global options] plan [options]\n\n  Generates a speculative execution plan, showing what actions Terraform\n  would take to apply the current configuration. This command will not\n  actually perform the planned actions.\n\n  You can optionally save the plan to a file, which you can then pass to\n  the \"apply\" command to perform exactly the actions described in the plan.\n\nPlan Customization Options:","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/plan.go#L172-L208","documentation":"Wrapped error from PlanCommand.operation during plan setup when c.initConfigLoader() fails. The config loader must exist before the plan operation can parse configuration, load modules, and resolve providers. Failure here aborts plan before any diffing. The %s (not %w) embeds the NewLoader error text into diagnostics.","triggerScenarios":"Running 'terraform plan' when configload.NewLoader errors — bad CLI config, inaccessible modules directory, or services/registry client init failure. Reachable because operation() calls initConfigLoader unconditionally for plan.","commonSituations":"TF_CLI_CONFIG_FILE points to unreadable/invalid HCL; data directory (.terraform) missing or read-only in CI; registry client cannot resolve services due to network/proxy issues; container lacks write access to the working directory.","solutions":["Read the embedded error string to identify the loader's underlying cause.","Fix or remove TF_CLI_CONFIG_FILE / ~/.terraformrc; ensure it is valid and readable.","Ensure TF_DATA_DIR / .terraform is writable and the working directory is accessible.","Run with TF_LOG=trace to capture the exact NewLoader failure point."],"exampleFix":"// before: read-only .terraform dir in CI\n// after: ensure writable data dir\n$ rm -rf .terraform && terraform init && terraform plan","handlingStrategy":"validation","validationCode":"// Pre-flight before 'terraform plan': ensure CLI config readable and data dir writable\npackage main\n\nfunc preflightPlan(cliConfig, dataDir string) error {\n\tif cliConfig != \"\" {\n\t\tif _, err := os.ReadFile(cliConfig); err != nil {\n\t\t\treturn fmt.Errorf(\"cli config 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 'terraform plan' in fresh environments.","Keep TF_CLI_CONFIG_FILE valid and version-controlled.","Ensure CI runners have a writable working/data directory."],"tags":["config-loader","plan","cli-config","initialization"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}