{"record":{"id":"d19e61b034945cd7","repo":"hashicorp/terraform","slug":"failed-to-initialize-config-loader-s-d19e61","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/refresh.go","lineNumber":161,"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 *RefreshCommand) Help() string {\n\thelpText := `\nUsage: terraform [global options] refresh [options]\n\n  Update the state file of your infrastructure with metadata that matches\n  the physical resources they are tracking.\n\n  This will not modify your infrastructure, but it can modify your\n  state file to update metadata. This metadata might cause new changes\n  to occur when you generate a plan or call apply next.\n\nOptions:","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/refresh.go#L143-L179","documentation":"Wrapped error from RefreshCommand.operation when c.initConfigLoader() fails. Refresh updates state metadata against real resources and requires the config loader to parse the configuration (to know which resources to refresh). Failure here prevents the operation from being submitted. %s embeds the NewLoader error.","triggerScenarios":"Running 'terraform refresh' when configload.NewLoader errors — invalid CLI config, inaccessible modules directory, or services/registry init failure.","commonSituations":"Identical root causes to 727/729: unreadable TF_CLI_CONFIG_FILE, read-only .terraform dir in CI, network blocking services discovery, container lacks write access.","solutions":["Read the embedded error to find the underlying loader cause.","Repair or unset TF_CLI_CONFIG_FILE; ensure ~/.terraformrc is valid.","Make the working/data directory writable.","Run with TF_LOG=trace for the precise failure."],"exampleFix":"// before\n$ terraform refresh\nFailed to initialize config loader: ...\n// after\n$ chmod -R u+w .terraform && terraform init && terraform refresh","handlingStrategy":"validation","validationCode":"// Same preflight as plan/query: CLI config + data dir\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 'terraform refresh'.","Prefer 'terraform apply -refresh-only' over standalone refresh where supported.","Keep CLI config valid and the working/data directory writable."],"tags":["config-loader","refresh","cli-config","initialization"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}