hashicorp/terraform · error
Failed to initialize config loader: %s
Error message
Failed to initialize config loader: %s
What it means
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.
Source
Thrown at internal/command/plan.go:190
// EXPERIMENTAL: maybe enable deferred actions
if c.AllowExperimentalFeatures {
opReq.DeferralAllowed = args.DeferralAllowed
} else if args.DeferralAllowed {
// Belated flag parse error, since we don't know about experiments
// support at actual parse time.
diags = diags.Append(tfdiags.Sourceless(
tfdiags.Error,
"Failed to parse command-line flags",
"The -allow-deferral flag is only valid in experimental builds of Terraform.",
))
return nil, diags
}
var err error
opReq.ConfigLoader, err = c.initConfigLoader()
if err != nil {
diags = diags.Append(fmt.Errorf("Failed to initialize config loader: %s", err))
return nil, diags
}
return opReq, diags
}
func (c *PlanCommand) Help() string {
helpText := `
Usage: terraform [global options] plan [options]
Generates a speculative execution plan, showing what actions Terraform
would take to apply the current configuration. This command will not
actually perform the planned actions.
You can optionally save the plan to a file, which you can then pass to
the "apply" command to perform exactly the actions described in the plan.
Plan Customization Options:View on GitHub (pinned to c9def3e214)
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.
Example fix
// before: read-only .terraform dir in CI // after: ensure writable data dir $ rm -rf .terraform && terraform init && terraform plan
Defensive patterns
Strategy: validation
Validate before calling
// Pre-flight before 'terraform plan': ensure CLI config readable and data dir writable
package main
func preflightPlan(cliConfig, dataDir string) error {
if cliConfig != "" {
if _, err := os.ReadFile(cliConfig); err != nil {
return fmt.Errorf("cli config unreadable: %w", err)
}
}
if err := os.MkdirAll(dataDir, 0o755); err != nil {
return fmt.Errorf("data dir not writable: %w", err)
}
return nil
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to initialize config loader: %w
- Failed to initialize config loader: %s
- Failed to initialize config loader: %s
- Failed to initialize config loader: %s
- error loading plugin path: %s
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/5ace502b255bb33e.
Report an issue: GitHub.