{"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":"exception","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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/refresh.go#L143-L179","documentation":"RefreshCommand opReq construction calls c.initConfigLoader(); on failure the error is wrapped and the refresh operation request cannot be built. Same pattern as plan/query. Note refresh is deprecated in favor of 'terraform apply -refresh-only'.","triggerScenarios":"terraform refresh is invoked; c.initConfigLoader() returns err — HCL parse errors, unreadable config directory, or inconsistent module installer state.","commonSituations":"Editing .tf files introducing syntax errors then running refresh; running refresh outside the config directory; partial init; removed or renamed files still referenced.","solutions":["Run terraform fmt and terraform validate before refresh.","Run terraform init to ensure the loader is ready.","Prefer 'terraform apply -refresh-only' as refresh is deprecated.","Inspect the inner %s for the exact loader failure location."],"exampleFix":"# before: deprecated refresh fails on parse error\nterraform refresh\n# after\nterraform fmt\nterraform apply -refresh-only","handlingStrategy":"validation","validationCode":"// Surface parse errors before refresh.\nif exit := runTerraform(\"validate\"); exit != 0 {\n    return fmt.Errorf(\"fix validate errors before refreshing\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer 'terraform apply -refresh-only' over the deprecated refresh command.","Always terraform fmt and validate first.","Run from the config root or use -chdir."],"tags":["terraform","config-loader","refresh","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"}