{"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":"exception","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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/plan.go#L172-L208","documentation":"PlanCommand opReq construction calls c.initConfigLoader(); failure is wrapped and the plan operation request cannot be built. The -allow-deferral guard above it returns a separate Sourceless diagnostic; this error specifically covers loader construction failures such as unparseable config or missing module path.","triggerScenarios":"terraform plan is invoked; c.initConfigLoader() returns err — HCL parse errors in .tf files, unreadable config directory, or module installer state that cannot be initialized.","commonSituations":"Plan after editing .tf files with syntax errors; running plan outside the config dir; partial terraform init leaving loader state inconsistent; config references files that no longer exist.","solutions":["Run terraform fmt and terraform validate to surface and fix HCL errors first.","Run terraform init to ensure modules and the loader are prepared.","Invoke plan from the configuration root or use -chdir.","Read the inner %s error for the exact file/line that broke parsing."],"exampleFix":"# before: plan fails on parse error\nterraform plan\n# after: fix first\nterraform fmt\nterraform validate\nterraform plan","handlingStrategy":"validation","validationCode":"// Run validate before plan to surface parse errors early.\nif exit := runTerraform(\"validate\"); exit != 0 {\n    return fmt.Errorf(\"configuration invalid; fix errors reported by 'terraform validate'\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run terraform fmt + terraform validate in CI before plan.","Run plan from the config root or use -chdir.","Keep terraform init current after module/backend changes."],"tags":["terraform","config-loader","plan","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"}