{"record":{"id":"762fec2a4246a9a2","repo":"hashicorp/terraform","slug":"error-getting-pwd-s-762fec","errorCode":null,"errorMessage":"Error getting pwd: %s","messagePattern":"Error getting pwd: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta.go","lineNumber":858,"sourceCode":"// code paths which use these arguments to be passed them directly for clarity.\nfunc (m *Meta) applyStateArguments(args *arguments.State) {\n\tm.stateLock = args.Lock\n\tm.stateLockTimeout = args.LockTimeout\n\tm.statePath = args.StatePath\n\tm.stateOutPath = args.StateOutPath\n\tm.backupPath = args.BackupPath\n}\n\n// checkRequiredVersion loads the config and check if the\n// core version requirements are satisfied.\nfunc (m *Meta) checkRequiredVersion() tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\n\t// Cannot use m.WorkingDir.RootModuleDir() here because\n\t// of path normalization that happens in loadConfig.\n\tpwd, err := os.Getwd()\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Error getting pwd: %s\", err))\n\t\treturn diags\n\t}\n\n\tdiags = diags.Append(m.resolveConstVariables(pwd, arguments.ViewHuman))\n\tif diags.HasErrors() {\n\t\treturn diags\n\t}\n\n\tconfig, configDiags := m.loadConfig(pwd)\n\tif configDiags.HasErrors() {\n\t\tdiags = diags.Append(configDiags)\n\t\treturn diags\n\t}\n\n\tversionDiags := terraform.CheckCoreVersionRequirements(config)\n\tif versionDiags.HasErrors() {\n\t\tdiags = diags.Append(versionDiags)\n\t\treturn diags","sourceCodeStart":840,"sourceCodeEnd":876,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta.go#L840-L876","documentation":"Returned from `Meta.checkRequiredVersion` when `os.Getwd()` fails. Before loading any Terraform config to evaluate `required_version` constraints, the command needs the current working directory; if the OS cannot return it, version checking aborts with this diagnostic.","triggerScenarios":"`os.Getwd()` returns an error when the current working directory has been deleted out from under the process, when a parent directory has its read/execute permission revoked, or on platforms where the cwd inode can no longer be resolved (e.g. a removed tmpfs mount).","commonSituations":"Running Terraform from a directory that was deleted or moved by another process mid-session; a wrapper script that `cd`s into a temp dir it then `rm -rf`s; filesystem permission changes; container/namespace filesystem teardown.","solutions":["Re-run the command from a directory that still exists and is accessible: `cd` to a valid path first.","If a script deleted its own cwd, fix the script to `cd` to a stable directory before invoking Terraform.","Check parent directory permissions: `ls -la` on each ancestor to ensure execute (`x`) bits are present.","Avoid running Terraform inside a directory managed by a cleanup tool or ephemeral mount."],"exampleFix":"# before: invoked after cwd was deleted\nterraform plan\n# after: move to an existing dir first\ncd \"$HOME/project\" && terraform plan","handlingStrategy":"validation","validationCode":"// Ensure cwd exists and is accessible before invoking terraform.\nwd, err := os.Getwd()\nif err != nil {\n    if err := os.Chdir(fallbackDir); err != nil { return err }\n}","typeGuard":"null","tryCatchPattern":"// os.Getwd errors are not retryable; the caller must chdir to a valid directory.","preventionTips":["Do not delete or unmount the directory Terraform is running in.","In scripts, `cd` to a stable, long-lived directory before invoking Terraform.","Avoid running Terraform from inside ephemeral temp dirs that get cleaned up."],"tags":["terraform","filesystem","cwd","os","config"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}