{"record":{"id":"8fb25a46d7f5c58c","repo":"hashicorp/terraform","slug":"error-loading-state-3-s-terraform-failed-t-8fb25a","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.","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\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend_migrate.go","lineNumber":736,"sourceCode":"\n\tsrcWord := backendHumanName(opts.Source)\n\tdstWord := backendHumanName(opts.Destination)\n\n\t// This map is used later when doing the migration per source/destination.\n\t// If a source has 'default' and has state, then we ask what the new name should be.\n\t// And further down when we actually run state migration for each\n\t// source/destination workspace, we use this new name (where source is 'default')\n\t// and set as destinationWorkspace. If the default workspace does not have\n\t// state we will not prompt the user for a new name because empty workspaces\n\t// do not get migrated.\n\tdefaultNewName := map[string]string{}\n\tfor i := 0; i < len(sourceWorkspaces); i++ {\n\t\tif sourceWorkspaces[i] == backend.DefaultStateName {\n\t\t\t// For the default workspace we want to look to see if there is any state\n\t\t\t// before we ask for a workspace name to migrate the default workspace into.\n\t\t\tsourceState, sDiags := opts.Source.StateMgr(backend.DefaultStateName)\n\t\t\tif sDiags.HasErrors() {\n\t\t\t\treturn fmt.Errorf(strings.TrimSpace(\n\t\t\t\t\terrMigrateSingleLoadDefault), opts.SourceType, srcWord, sDiags.Err())\n\t\t\t}\n\t\t\t// RefreshState is what actually pulls the state to be evaluated.\n\t\t\tif err := sourceState.RefreshState(); err != nil {\n\t\t\t\treturn fmt.Errorf(strings.TrimSpace(\n\t\t\t\t\terrMigrateSingleLoadDefault), opts.SourceType, srcWord, err)\n\t\t\t}\n\t\t\tif !sourceState.State().Empty() {\n\t\t\t\tnewName, err := m.promptNewWorkspaceName(opts.DestinationType, dstWord)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\t\t\t\tdefaultNewName[sourceWorkspaces[i]] = newName\n\t\t\t}\n\t\t}\n\t}\n\n\t// Fetch the pattern that will be used to rename the workspaces for HCP Terraform or Terraform Enterprise.","sourceCodeStart":718,"sourceCodeEnd":754,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_backend_migrate.go#L718-L754","documentation":"During TFC migration with a single default workspace, Terraform calls opts.Source.StateMgr(backend.DefaultStateName) to obtain a state manager for the default workspace. If this call returns diagnostics with errors (sDiags.HasErrors()), the state manager cannot be constructed and migration aborts. Both source and destination states remain unmodified.","triggerScenarios":"Running `terraform init` after reconfiguring the backend when the source backend cannot initialize its state manager for the default workspace — typically due to authentication, lock contention, or configuration errors at the state manager level.","commonSituations":"Locked state in the source backend (another Terraform process is running), stale or rotated credentials, backend configuration mismatch (wrong path/key in state storage), permissions changed on the state storage object, or the backend service is degraded.","solutions":["Check for and force-unlock any stale state locks in the source backend (`terraform force-unlock` if applicable)","Verify source backend authentication is working and credentials have not expired","Confirm the state storage path/key/bucket configuration is correct and accessible","Test the backend connection independently (e.g., `aws s3 ls` for S3 backends) before retrying `terraform init`","Clear any local backend cache with `terraform init -reconfigure` if the backend config was recently edited"],"exampleFix":"# before: state lock or auth error blocks default state load\nterraform init\n# after: unlock and retry\nterraform force-unlock <LOCK_ID> && terraform init","handlingStrategy":"validation","validationCode":"// Verify state manager can be constructed for the default workspace before migration\nfunc checkStateMgr(back backend.Backend, workspace string) error {\n    sm, diags := back.StateMgr(workspace)\n    if diags.HasErrors() {\n        return fmt.Errorf(\"cannot construct state manager for %q: %w\", workspace, diags.Err())\n    }\n    _ = sm // state manager is ready\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure no stale state locks exist before backend migration — run `terraform force-unlock` if needed","Verify source backend authentication is current before running init","Test StateMgr construction on the default workspace before committing to migration","Use `terraform init -reconfigure` to get a clean backend connection"],"tags":["backend","migration","state","default-workspace","state-lock"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}