{"record":{"id":"8587b5693f174563","repo":"hashicorp/terraform","slug":"failed-to-refresh-module-manifest-w","errorCode":null,"errorMessage":"Failed to refresh module manifest: %w","messagePattern":"Failed to refresh module manifest: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/modules.go","lineNumber":138,"sourceCode":"\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:\n\n  -json               If specified, output declared Terraform modules and\n                      their resolved versions in a machine-readable format.\n\n  -var 'foo=bar'      Set a value for one of the input variables in the root","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/modules.go#L120-L156","documentation":"After the config loader initializes successfully, ModulesCommand.internalManifest calls loader.RefreshModules() to reconcile the on-disk module manifest with installed modules. A non-nil error here is wrapped and the manifest read is aborted. This is the refresh/install step, not the read step.","triggerScenarios":"loader.RefreshModules() returns an error — typically network failure reaching a module registry, a git source that cannot be cloned, a removed module version, or a corrupt manifest file under .terraform/modules.","commonSituations":"Running `terraform modules` after a partial/failed terraform init; module source URL changed or went private; offline environment without the modules cached; .terraform/modules/modules.json corrupted.","solutions":["Run terraform init -upgrade to re-fetch and refresh module sources cleanly.","Check network/registry access and credentials for any module source (git, registry, s3).","Remove .terraform/modules and re-run terraform init to rebuild the manifest.","Pin module source versions so refresh resolves deterministically."],"exampleFix":"# before: refresh fails on stale manifest\n# after\nrm -rf .terraform/modules\nterraform init\nterraform modules","handlingStrategy":"retry","validationCode":"// Pre-flight network/registry reachability for module sources.\nif isGitSource(moduleSrc) && !gitReachable(moduleSrc) {\n    return fmt.Errorf(\"module source unreachable: %s\", moduleSrc)\n}","typeGuard":null,"tryCatchPattern":"// Module refresh failures are often transient (registry flakiness).\nif refreshErr := loader.RefreshModules(); refreshErr != nil {\n    time.Sleep(backoff)\n    refreshErr = loader.RefreshModules() // one bounded retry\n}","preventionTips":["Run terraform init before `terraform modules`.","Pin module versions and mirror registries in air-gapped environments.","Keep .terraform/modules consistent with the configuration."],"tags":["terraform","module","init","registry","network"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}