{"record":{"id":"1a2698ecc9781d88","repo":"hashicorp/terraform","slug":"error-loading-state-3-s-terraform-failed-t","errorCode":null,"errorMessage":"Error loading state:\n    %[3]s\n\nTerraform failed to load the default state from the %[1]q %[2]s.\nState migration cannot occur unless the state can be loaded.\nState migration has been aborted. The state in both the\nsource and the destination remain unmodified. Please resolve the\nabove error and try again.\n","messagePattern":"Error loading state:\n    %\\[3\\]s\n\nTerraform failed to load the default state from the %\\[1\\]q %\\[2\\]s\\.\nState migration cannot occur unless the state can be loaded\\.\nState migration has been aborted\\. The state in both the\nsource and the destination remain unmodified\\. Please resolve the\nabove error and try again\\.\n","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend_migrate.go","lineNumber":279,"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\tsrcWord := backendHumanName(opts.Source)\n\tdstWord := backendHumanName(opts.Destination)\n\n\tvar err error\n\tdestinationState, sDiags := opts.Destination.StateMgr(opts.destinationWorkspace)","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend_migrate.go#L261-L297","documentation":"Returned by the single-to-single migration when the source state manager cannot be obtained (`opts.Source.StateMgr(...)` returns error diagnostics). Terraform cannot begin migration without a readable source state, so it aborts with both backends unmodified.","triggerScenarios":"Fires at the top of `backendMigrateState_s_s` when `opts.Source.StateMgr(opts.sourceWorkspace)` returns diagnostics with errors — invalid workspace name, backend misconfiguration, or auth failure constructing the manager.","commonSituations":"Backend `key`/`workspace` path is malformed, the source backend's config references a missing bucket/container, or constructing the state client fails due to expired credentials.","solutions":["Validate the source backend block (`terraform init -backend=false` to isolate, then re-enable).","Confirm the source workspace/key exists and the configured identity can read it.","Re-authenticate and retry `terraform init`.","Inspect the embedded `%[3]s` diagnostic for the precise backend-reported cause."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Validate the source backend can construct a state manager before init:\n# confirm bucket/key/workspace resolve and identity has read access.\naws s3 ls \"s3://${SRC_BUCKET}/${SRC_KEY}\" >/dev/null \\\n  || echo \"source state object unreadable\"\nterraform init","typeGuard":null,"tryCatchPattern":"# Source construction failure is usually config/auth, not transient:\nif ! terraform init -input=false >/tmp/init.log 2>&1; then\n  grep -q 'Error loading state' /tmp/init.log \\\n    && { echo 'Source backend config/auth invalid' >&2; exit 2; }\n  cat /tmp/init.log; exit 1\nfi","preventionTips":["Keep backend config in VCS and review changes that alter key/workspace paths.","Refresh credentials immediately before init in CI.","Run `terraform init -backend=false` to isolate config-vs-backend issues."],"tags":["backend","migration","single-state","state-load","credentials","init"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}