{"record":{"id":"3ec249bf50dafaaa","repo":"hashicorp/terraform","slug":"error-inspecting-states-in-the-q-backend-s","errorCode":null,"errorMessage":"Error inspecting states in the %q backend:\n    %s\n\nPrior to changing backends, Terraform inspects the source and destination\nstates to determine what kind of migration steps need to be taken, if any.\nTerraform failed to load the states. The data in both the source and the\ndestination remain unmodified. Please resolve the above error and try again.","messagePattern":"Error inspecting states in the %q backend:\n    (.+?)\n\nPrior to changing backends, Terraform inspects the source and destination\nstates to determine what kind of migration steps need to be taken, if any\\.\nTerraform failed to load the states\\. The data in both the source and the\ndestination remain unmodified\\. Please resolve the above error and try again\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_backend_migrate.go","lineNumber":192,"sourceCode":"\t\t\t\t\"Do you want to migrate all workspaces to %q?\",\n\t\t\t\topts.DestinationType),\n\t\t\tDescription: fmt.Sprintf(\n\t\t\t\tstrings.TrimSpace(inputBackendMigrateMultiToMulti),\n\t\t\t\topts.SourceType, opts.DestinationType),\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\n\t\t\t\t\"Error asking for state migration action: %s\", err)\n\t\t}\n\t}\n\tif !migrate {\n\t\treturn fmt.Errorf(\"Migration aborted by user.\")\n\t}\n\n\t// Read all the states\n\tsourceWorkspaces, wDiags := opts.Source.Workspaces()\n\tif wDiags.HasErrors() {\n\t\treturn fmt.Errorf(strings.TrimSpace(\n\t\t\terrMigrateLoadStates), opts.SourceType, wDiags.Err())\n\t}\n\tif wDiags.HasWarnings() {\n\t\tlog.Printf(\"[WARN] backendMigrateState_S_S: warning(s) returned when getting workspaces from source backend: %s\", wDiags.ErrWithWarnings())\n\t}\n\n\t// Sort the states so they're always copied alphabetically\n\tsort.Strings(sourceWorkspaces)\n\n\t// Go through each and migrate\n\tfor _, name := range sourceWorkspaces {\n\t\t// Copy the same names\n\t\topts.sourceWorkspace = name\n\t\topts.destinationWorkspace = name\n\n\t\t// Force it, we confirmed above\n\t\topts.force = true\n","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_backend_migrate.go#L174-L210","documentation":"In Meta.backendMigrateState_S_S (meta_backend_migrate.go:192), after the user agreed to migrate all workspaces, Terraform calls opts.Source.Workspaces() to enumerate the source backend's states. If listing fails, init aborts with this message. The message stresses that neither source nor destination data is modified by the inspection step, so this is safe to retry after fixing the underlying access problem.","triggerScenarios":"The SOURCE backend cannot enumerate its workspaces/states due to auth, network, permissions, or a backend-side error (e.g. cannot list S3 keys/DynamoDB entries, cannot reach Consul/HTTP/Azure/GCS); the source credentials are wrong or expired.","commonSituations":"Expired/temporary credentials for the source backend, insufficient IAM/list permissions, a source bucket/endpoint that no longer exists, or a transient outage during migration.","solutions":["Read the wrapped error from Source.Workspaces() for the backend-specific cause (AccessDenied, 404, timeout).","Verify source-backend credentials and that the principal can LIST states/workspaces (not just read one).","Confirm the source backend endpoint/bucket/path still exists and is reachable, then retry init.","Reassure: the message confirms source and destination remain unmodified, so retrying is safe once access is fixed."],"exampleFix":"// before: terraform init -migrate-state   (fails: Error inspecting states in the 'remote' backend: AccessDenied)\n// after: # grant list on source backend, then retry\nterraform init -migrate-state","handlingStrategy":"validation","validationCode":"// Before migrating, confirm the SOURCE backend can enumerate its workspaces.\nfunc sourceCanListWorkspaces(src backend.Backend) error {\n    diags := src.Workspaces()\n    if diags.HasErrors() { return fmt.Errorf(\"source backend cannot list workspaces: %w\", diags.Err()) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Listing failures are often transient; the inspection step modifies nothing, so retry is safe.\nif err := cmd.Init(); err != nil && strings.Contains(err.Error(), \"Error inspecting states\") {\n    time.Sleep(backoff); return cmd.Init()\n}","preventionTips":["Grant the source-backend principal LIST (not just read) permissions on states/workspaces.","Use fresh, non-expired credentials for the source backend before migrating.","Confirm the source endpoint/bucket/path exists before migrating.","Retry safely: the message confirms source and destination remain unmodified on inspection failure."],"tags":["state","migration","backend","auth","list-workspaces"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}