{"record":{"id":"762fec2a4246a9a2","repo":"hashicorp/terraform","slug":"error-getting-pwd-s-762fec","errorCode":null,"errorMessage":"Error getting pwd: %s","messagePattern":"Error getting pwd: (.+?)","errorType":"console","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta.go#L840-L876","documentation":"Appended as a diagnostic in checkRequiredVersion() when os.Getwd() fails. Terraform needs the current working directory to locate and load the root module configuration for version constraint checking. The %s wraps the OS-level error (errno) from getwd.","triggerScenarios":"The Go runtime's os.Getwd() returns an error, typically when the current working directory has been deleted out from under the process, when a parent directory has insufficient permissions, or on platforms where the cwd is represented by an unresolvable file descriptor.","commonSituations":"Running terraform from a directory that was since removed (common in CI when a prior step cleans the workspace); a mounted filesystem being unmounted mid-run; permission/ACL changes on a parent directory; a container where the cwd path no longer exists after a volume remount.","solutions":["Re-run from a directory that currently exists and is readable: cd to a valid path first.","In CI, ensure the working directory is not deleted between steps; avoid cleaning the workspace while a shell still has it as cwd.","Check parent directory permissions (chmod/chown) so the process can resolve its cwd."],"exampleFix":"// before: CI deletes workspace mid-pipeline\nrm -rf $WORKSPACE  # while shell cwd is there\nterraform plan\n// after: run terraform from a stable directory\ncd /opt/infra\nterraform plan","handlingStrategy":"validation","validationCode":"// Verify cwd is resolvable before launching terraform\nif _, err := os.Getwd(); err != nil {\n    log.Fatalf(\"current working directory unavailable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't delete the process's cwd between pipeline steps in CI.","Run terraform from a stable, existing directory.","Avoid unmounting or chmod-ing parent directories during a run."],"tags":["filesystem","cwd","permissions","ci"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}