{"record":{"id":"850fcbdb129fe0bb","repo":"hashicorp/terraform","slug":"error-loading-state-2-s-terraform-failed-t","errorCode":null,"errorMessage":"Error loading state:\n    %[2]s\n\nTerraform failed to load the default state from the %[1]q backend.\nState migration cannot occur unless the state can be loaded. Backend\nmodification and state migration has been aborted. The state in both the\nsource and the destination remain unmodified. Please resolve the\nabove error and try again.","messagePattern":"Error loading state:\n    %\\[2\\]s\n\nTerraform failed to load the default state from the %\\[1\\]q backend\\.\nState migration cannot occur unless the state can be loaded\\. Backend\nmodification and state migration has been aborted\\. The state in both the\nsource and the destination remain unmodified\\. Please resolve the\nabove error and try again\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend_migrate.go","lineNumber":269,"sourceCode":"\t\treturn fmt.Errorf(\"Migration aborted by user.\")\n\t}\n\n\t// Copy the default state\n\topts.sourceWorkspace = currentWorkspace\n\n\t// now switch back to the default env so we can acccess the new backend\n\tm.SetWorkspace(backend.DefaultStateName)\n\n\treturn m.backendMigrateState_s_s(opts)\n}\n\n// Single state to single state, assumed default state name.\nfunc (m *Meta) backendMigrateState_s_s(opts *backendMigrateOpts) error {\n\tlog.Printf(\"[INFO] backendMigrateState: single-to-single migrating %q workspace to %q workspace\", opts.sourceWorkspace, opts.destinationWorkspace)\n\n\tsourceState, sDiags := opts.Source.StateMgr(opts.sourceWorkspace)\n\tif sDiags.HasErrors() {\n\t\treturn fmt.Errorf(strings.TrimSpace(\n\t\t\terrMigrateSingleLoadDefault), opts.SourceType, sDiags.Err())\n\t}\n\tif err := sourceState.RefreshState(); err != nil {\n\t\treturn fmt.Errorf(strings.TrimSpace(\n\t\t\terrMigrateSingleLoadDefault), opts.SourceType, err)\n\t}\n\n\t// Do not migrate workspaces without state.\n\tif sourceState.State().Empty() {\n\t\tlog.Print(\"[TRACE] backendMigrateState: source workspace has empty state, so nothing to migrate\")\n\t\treturn nil\n\t}\n\n\tvar err error\n\tdestinationState, sDiags := opts.Destination.StateMgr(opts.destinationWorkspace)\n\tif sDiags.HasErrors() {\n\t\tif sDiags.Err().Error() == backend.ErrDefaultWorkspaceNotSupported.Error() {\n\t\t\t// If the backend doesn't support using the default state, we ask the user","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend_migrate.go#L251-L287","documentation":"Returned by backendMigrateState_s_s (single-to-single) when obtaining the source workspace's StateMgr fails with diagnostics errors — i.e., opts.Source.StateMgr(opts.sourceWorkspace) at line 267 returns HasErrors. The migration cannot proceed because the source state manager (the reader) could not even be constructed, so nothing is read or written.","triggerScenarios":"The source backend's StateMgr factory rejects the workspace name or backend config — e.g., invalid workspace name, backend misconfiguration (bad credentials resolved at StateMgr time), or the backend type doesn't accept the requested workspace. Error is wrapped at line 269 using opts.SourceType and the diagnostics error.","commonSituations":"Backend block has a typo or stale credentials; source workspace name contains characters the backend rejects; source is an S3/local backend whose configuration references a missing path or bucket; migrating after the source credentials expired.","solutions":["Inspect the %[2]s inner error for the exact StateMgr construction failure.","Verify the source backend block configuration (credentials, endpoint, bucket, path, key).","Confirm the current workspace name is valid: run 'terraform workspace list' against the source.","Re-authenticate / refresh credentials for the source backend, then re-run 'terraform init'.","If the source state file is local, ensure the file exists at the configured path and is readable."],"exampleFix":"// before: source S3 backend StateMgr fails on stale credentials\n//   backend \"s3\" { bucket = \"tf-state\" ... }  // old creds\n// fix: refresh creds and retry\n//   aws s3 ls s3://tf-state  # verify access\n//   terraform init","handlingStrategy":"validation","validationCode":"# Validate source backend config and StateMgr reachability before init.\n# For S3: confirm bucket + key readable with the configured identity.\naws sts get-caller-identity >/dev/null || { echo 'creds invalid'; exit 1; }\naws s3api head-object --bucket \"$TF_SRC_BUCKET\" --key \"$TF_SRC_KEY\" >/dev/null 2>&1 \\\n  || echo 'warn: source key not readable'\n# Then run init.\nterraform init","typeGuard":null,"tryCatchPattern":"# Surface source StateMgr construction failures distinctly.\nterraform init 2>/tmp/init.err || rc=$?\nif grep -q 'failed to load the default state' /tmp/init.err; then\n  echo 'Source StateMgr construction failed — check source backend block + creds' >&2\nfi\nexit ${rc:-0}","preventionTips":["Run 'terraform validate' on the backend config before init.","Pre-flight credential check (aws sts / cloud auth) for the source backend.","Confirm the current workspace name is valid via 'terraform workspace list'.","Keep backend blocks in version control and review changes (diff the backend block) before migrating."],"tags":["backend","state-migration","statemgr","source-backend","credentials","terraform-init"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}