{"record":{"id":"80178c21bb3961d8","repo":"hashicorp/terraform","slug":"failed-to-initialize-config-loader-w","errorCode":null,"errorMessage":"Failed to initialize config loader: %w","messagePattern":"Failed to initialize config loader: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/modules.go","lineNumber":133,"sourceCode":"\n\t// Create a module reference resolver\n\tresolver := moduleref.NewResolver(internalManifest)\n\n\t// Crawl the Terraform config and find entries with references\n\tmanifestWithRef := resolver.Resolve(config)\n\n\t// Render the new manifest with references\n\treturn view.Display(*manifestWithRef)\n}\n\n// internalManifest will use the configuration loader to refresh and load the\n// internal manifest.\nfunc (c *ModulesCommand) internalManifest() (modsdir.Manifest, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\tloader, err := c.initConfigLoader()\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to initialize config loader: %w\", err))\n\t\treturn nil, diags\n\t}\n\n\tif err = loader.RefreshModules(); err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to refresh module manifest: %w\", err))\n\t\treturn nil, diags\n\t}\n\n\treturn loader.ModuleManifest(), diags\n}\n\nconst modulesCommandHelp = `\nUsage: terraform [global options] modules [options]\n\n  Prints out a list of all declared Terraform modules and their resolved versions\n  in a Terraform working directory.\n\nOptions:","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/modules.go#L115-L151","documentation":"ModulesCommand.internalManifest calls c.initConfigLoader() to obtain the config loader used to refresh and read the module manifest. If initialization fails (the config tree cannot be parsed, the module path is invalid, or required helpers are missing) the error is appended to diagnostics and returned, aborting `terraform modules`.","triggerScenarios":"Running `terraform modules`; initConfigLoader() returns a non-nil error, which propagates from parser/loader construction, module installation bookkeeping, or a missing configuration directory.","commonSituations":"Invoking `terraform modules` outside a Terraform configuration directory; configuration has HCL syntax errors; required_providers/module blocks reference unreachable sources; permissions on the config dir prevent reading.","solutions":["Run the command from the directory containing the root module (.tf files).","Run terraform init first so module installation and the loader state are prepared.","Fix any HCL syntax errors surfaced by the embedded %w error.","Pass an explicit -chdir to point at the configuration root if your cwd differs."],"exampleFix":"# before: run from wrong directory\nterraform modules\n# after\ncd infra/live && terraform modules\n# or\nterraform -chdir=infra/live modules","handlingStrategy":"validation","validationCode":"// Ensure cwd is a config root before invoking `terraform modules`.\nif _, err := os.Stat(\"main.tf\"); err != nil {\n    return fmt.Errorf(\"no .tf files in cwd; pass -chdir or cd into the config root\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run `terraform modules` after `terraform init`.","Run Terraform commands from the configuration root or use -chdir.","Validate configuration with terraform validate first."],"tags":["terraform","config-loader","module","cli"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}