{"record":{"id":"2a1adcf3da43e3fd","repo":"hashicorp/terraform","slug":"error-creating-temporary-directory-s","errorCode":null,"errorMessage":"Error creating temporary directory: %s","messagePattern":"Error creating temporary directory: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend_migrate.go","lineNumber":507,"sourceCode":"\t\t\tDescription: fmt.Sprintf(\n\t\t\t\tstrings.TrimSpace(inputBackendMigrateEmpty),\n\t\t\t\topts.SourceType, opts.DestinationType),\n\t\t}\n\t}\n\n\treturn m.confirm(inputOpts)\n}\n\nfunc (m *Meta) backendMigrateNonEmptyConfirm(\n\tsourceState, destinationState statemgr.Full, opts *backendMigrateOpts) (bool, error) {\n\t// We need to grab both states so we can write them to a file\n\tsource := sourceState.State()\n\tdestination := destinationState.State()\n\n\t// Save both to a temporary\n\ttd, err := os.MkdirTemp(\"\", \"terraform\")\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"Error creating temporary directory: %s\", err)\n\t}\n\tdefer os.RemoveAll(td)\n\n\t// Helper to write the state\n\tsaveHelper := func(n, path string, s *states.State) error {\n\t\tmgr := statemgr.NewFilesystem(path)\n\t\treturn mgr.WriteState(s)\n\t}\n\n\t// Write the states\n\tsourcePath := filepath.Join(td, fmt.Sprintf(\"1-%s.tfstate\", opts.SourceType))\n\tdestinationPath := filepath.Join(td, fmt.Sprintf(\"2-%s.tfstate\", opts.DestinationType))\n\tif err := saveHelper(opts.SourceType, sourcePath, source); err != nil {\n\t\treturn false, fmt.Errorf(\"Error saving temporary state: %s\", err)\n\t}\n\tif err := saveHelper(opts.DestinationType, destinationPath, destination); err != nil {\n\t\treturn false, fmt.Errorf(\"Error saving temporary state: %s\", err)\n\t}","sourceCodeStart":489,"sourceCodeEnd":525,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend_migrate.go#L489-L525","documentation":"Returned by backendMigrateNonEmptyConfirm when os.MkdirTemp(\"\", \"terraform\") at line 505 fails. This helper builds the confirmation prompt when both source and destination have non-empty state — it writes both states to temp files so the user can compare them. The temp directory creation failed.","triggerScenarios":"The OS cannot create a temp directory under the system temp dir (os.TempDir): no space left on /tmp (ENOSPC), permission denied creating under TMPDIR, read-only /tmp in a hardened container, or the process ulimit on files/dirs is exhausted. Wrapped at line 507.","commonSituations":"CI runner with full /tmp; container with read-only /tmp mount; SELinux/AppArmor denying tempdir creation; low inodes; running as a user without write access to TMPDIR.","solutions":["Free space or inodes on the volume backing the temp directory (often /tmp).","Set TMPDIR to a writable location with space: 'export TMPDIR=/path/to/writable/dir'.","Ensure the user running terraform has write permission on the temp dir.","In containers, mount /tmp as read-write with adequate size.","If disk pressure is chronic, clean up old terraform temp dirs (/tmp/terraform*)."],"exampleFix":"# before: /tmp full -> Error creating temporary directory: ... no space\n# after: point TMPDIR at a volume with space\nexport TMPDIR=/var/tmp/opencode\nterraform init","handlingStrategy":"validation","validationCode":"# Ensure a writable temp dir with space before running init.\nmkdir -p \"${TMPDIR:-/tmp}\" && : > \"${TMPDIR:-/tmp}/.tfprobe\" \\\n  || { export TMPDIR=\"$HOME/.tf-tmp\"; mkdir -p \"$TMPDIR\"; }\ndf -h \"${TMPDIR:-/tmp}\" | awk 'NR==2{if($5+0>90){print \"temp volume nearly full\"; exit 1}}'\nterraform init","typeGuard":null,"tryCatchPattern":"# Set a known-writable TMPDIR and retry.\nexport TMPDIR=\"${TF_TMPDIR:-$HOME/.tf-tmp}\"; mkdir -p \"$TMPDIR\"\nterraform init || terraform init  # second attempt on the corrected TMPDIR","preventionTips":["Set TMPDIR explicitly to a volume with headroom in CI.","Monitor disk usage on runners; alert above 80%.","Clean /tmp/terraform* after each run.","Mount /tmp read-write with adequate size in containers."],"tags":["backend","state-migration","filesystem","temp-dir","disk-full","permissions","confirmation-prompt"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}