{"record":{"id":"c501f00f025d424b","repo":"hashicorp/terraform","slug":"failed-to-read-module-manifest-s","errorCode":null,"errorMessage":"failed to read module manifest: %s","messagePattern":"failed to read module manifest: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/configs/configload/loader.go","lineNumber":92,"sourceCode":"\n\tparser := configs.NewParser(fs)\n\treg := registry.NewClient(config.Services, nil)\n\n\tret := &Loader{\n\t\tparser: parser,\n\t\tmodules: moduleMgr{\n\t\t\tFS:         afero.Afero{Fs: fs},\n\t\t\tCanInstall: true,\n\t\t\tDir:        config.ModulesDir,\n\t\t\tServices:   config.Services,\n\t\t\tRegistry:   reg,\n\t\t},\n\t\tparserOpts: make([]configs.Option, 0),\n\t}\n\n\terr := ret.modules.readModuleManifestSnapshot()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read module manifest: %s\", err)\n\t}\n\n\tif config.IncludeQueryFiles {\n\t\tret.parserOpts = append(ret.parserOpts, configs.MatchQueryFiles())\n\t}\n\n\tif config.IncludeStateMigrateFiles {\n\t\tret.parserOpts = append(ret.parserOpts, configs.MatchStateMigrateFiles())\n\t}\n\n\treturn ret, nil\n}\n\n// ModulesDir returns the path to the directory where the loader will look for\n// the local cache of remote module packages.\nfunc (l *Loader) ModulesDir() string {\n\treturn l.modules.Dir\n}","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/configs/configload/loader.go#L74-L110","documentation":"When constructing a config loader, Terraform reads the module manifest snapshot (a JSON file tracking installed modules under .terraform/modules/). If this file cannot be read or parsed — corrupt JSON, missing file when modules were partially installed, or a permission error — the loader cannot be created and the error propagates.","triggerScenarios":"Loader instantiation calls readModuleManifestSnapshot(), which fails. Triggered by: .terraform/modules/modules.json being corrupt or truncated, a partial terraform init that wrote a half-finished manifest, file permission issues on the modules directory, or a race condition where the manifest was being written when Terraform tried to read it.","commonSituations":"A previous terraform init was interrupted (Ctrl+C, crash, OOM kill), leaving a partial manifest file. The .terraform directory was partially deleted or restored from backup. Filesystem corruption on the modules directory. Concurrent Terraform processes racing on the same working directory.","solutions":["Run terraform init to regenerate the module manifest from scratch.","If .terraform is corrupt, remove it entirely: rm -rf .terraform && terraform init.","Check file permissions on .terraform/modules/modules.json and ensure the Terraform process can read it.","Avoid running multiple terraform init processes concurrently in the same working directory."],"exampleFix":"# before — partial/corrupt module manifest from interrupted init\nterraform plan  # → error\n\n# after — clean reinitialize\nrm -rf .terraform\nterraform init\nterraform plan","handlingStrategy":"validation","validationCode":"// Verify the module manifest is readable before plan\n// Shell pre-check:\n//   terraform init -input=false  # regenerates manifest if corrupt\n// If init itself fails:\n//   rm -rf .terraform && terraform init\n\n// Go-side (embedding Terraform): wrap loader creation in error handling\nloader, err := configload.NewLoader(cfg)\nif err != nil {\n    log.Printf(\"module manifest load failed, attempting clean init: %v\", err)\n    os.RemoveAll(filepath.Join(workingDir, \".terraform\"))\n    // re-run init, then retry\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid interrupting terraform init mid-run; if interrupted, clean .terraform before retrying.","Never partially restore .terraform from backup — either restore fully or re-init.","Do not run multiple terraform init processes concurrently in the same directory.","Add rm -rf .terraform as a recovery step in CI when init fails with manifest errors."],"tags":["config","modules","manifest","init","filesystem"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}