{"record":{"id":"e6961ec917ae0246","repo":"hashicorp/terraform","slug":"unable-to-locate-module-s","errorCode":null,"errorMessage":"unable to locate module: %s","messagePattern":"unable to locate module: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/validate.go","lineNumber":73,"sourceCode":"\n\tloader, err := c.initConfigLoader()\n\tif err != nil {\n\t\tdiags = diags.Append(err)\n\t\treturn view.Results(diags)\n\t}\n\n\tvar varDiags tfdiags.Diagnostics\n\tc.VariableValues, varDiags = args.Vars.CollectValues(func(filename string, src []byte) {\n\t\tloader.Parser().ForceFileSource(filename, src)\n\t})\n\tif varDiags.HasErrors() {\n\t\tdiags = diags.Append(varDiags)\n\t\treturn view.Results(diags)\n\t}\n\n\tdir, err := filepath.Abs(args.Path)\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"unable to locate module: %s\", err))\n\t\treturn view.Results(diags)\n\t}\n\n\t// Check for user-supplied plugin path\n\tif c.pluginPath, err = c.loadPluginPath(); err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"error loading plugin path: %s\", err))\n\t\treturn view.Results(diags)\n\t}\n\n\tvalidateDiags := c.validate(dir)\n\tdiags = diags.Append(validateDiags)\n\n\t// Validating with dev overrides in effect means that the result might\n\t// not be valid for a stable release, so we'll warn about that in case\n\t// the user is trying to use \"terraform validate\" as a sort of pre-flight\n\t// check before submitting a change.\n\tdiags = diags.Append(c.providerDevOverrideRuntimeWarnings())\n","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/validate.go#L55-L91","documentation":"Thrown by `terraform validate` when filepath.Abs(args.Path) fails. filepath.Abs only fails when the current working directory cannot be determined (os.Getwd fails), not for nonexistent input paths. The %s is the os error. Reaching this means Terraform itself lost track of its cwd.","triggerScenarios":"Running `terraform validate <path>` from a working directory that was deleted or made inaccessible between process start and the filepath.Abs call, or in a sandbox that reports no cwd.","commonSituations":"Running validate from a directory that a parallel process removed (e.g. rm -rf in CI); running inside a container where cwd was unmounted; shells whose cwd no longer exists; obscure OS/cwd permission errors.","solutions":["Ensure you run `terraform validate` from an existing, accessible directory: cd into a valid path first.","Pass an explicit absolute path argument so filepath.Abs does not depend on cwd: `terraform validate /abs/path`.","If in CI, verify the workspace checkout directory still exists at validate time (no cleanup racing the build)."],"exampleFix":"# before: cwd removed mid-run\n(cd /tmp/willbedeleted && rm -rf /tmp/willbedeleted && terraform validate)\n# unable to locate module: getwd: no such file or directory\n\n# after: pass an explicit existing path\nterraform validate /home/user/config","handlingStrategy":"validation","validationCode":"// ensure cwd exists before calling validate\nif _, err := os.Getwd(); err != nil {\n    // switch to a known-good directory or pass an absolute path\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run terraform from a stable, existing working directory.","Pass explicit absolute paths to `terraform validate`.","Don't delete the workspace directory while builds run in it.","In CI, verify the checkout dir exists at step start."],"tags":["validate","filesystem","working-directory"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}