{"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":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend_migrate.go","lineNumber":527,"sourceCode":"\t\t\t\tstrings.TrimSpace(inputBackendMigrateEmpty),\n\t\t\t\topts.SourceType, srcWord,\n\t\t\t\topts.DestinationType, dstWord),\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":509,"sourceCodeEnd":545,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend_migrate.go#L509-L545","documentation":"Returned by `backendMigrateNonEmptyConfirm` when creating a temp directory to dump both states for the side-by-side confirmation diff fails. `os.MkdirTemp(\"\", \"terraform\")` returned an error, so the non-empty confirmation flow cannot present the diff.","triggerScenarios":"Fires at the top of `backendMigrateNonEmptyConfirm` when `os.MkdirTemp` fails — OS-level temp space unavailable, `TMPDIR` pointing to a non-writable path, disk full, or the OS refusing the `terraform` prefix.","commonSituations":"CI runners with a full/no `/tmp`, containers with a read-only or small tmpfs, `TMPDIR` misconfigured to a non-existent directory, or SELinux/AppArmor denying temp creation.","solutions":["Free space in the system temp directory (`/tmp`) or remount tmpfs larger.","Set `TMPDIR` to a writable, spacious directory: `TMPDIR=/var/tmp terraform init`.","Run `terraform init` with `-force-copy` to skip the non-empty confirmation diff entirely.","Check filesystem permissions and disk space on the temp volume."],"exampleFix":"# before\nterraform init   # /tmp full\n# after\nmkdir -p /var/tmp/tf && TMPDIR=/var/tmp/tf terraform init -force-copy","handlingStrategy":"validation","validationCode":"# Ensure a writable temp dir with enough space before init.\nTMPDIR=${TMPDIR:-/tmp}\nmkdir -p \"$TMPDIR\" && touch \"$TMPDIR/.w\" && rm \"$TMPDIR/.w\" \\\n  || { echo \"TMPDIR $TMPDIR not writable\"; exit 1; }\ndf -h \"$TMPDIR\"  # confirm free space\nterraform init","typeGuard":null,"tryCatchPattern":"# Side-step the diff entirely when temp space is constrained:\nif ! terraform init >/tmp/init.log 2>&1; then\n  grep -q 'Error creating temporary directory' /tmp/init.log \\\n    && { echo 'Set TMPDIR or rerun with -force-copy' >&2; exit 2; }\n  cat /tmp/init.log; exit 1\nfi","preventionTips":["Set TMPDIR to a spacious writable volume in CI.","Use -force-copy to skip the non-empty confirmation diff.","Monitor free space on the temp filesystem in CI runners."],"tags":["backend","migration","temp-dir","filesystem","confirmation","init"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}