{"record":{"id":"e485a2c29180297c","repo":"hashicorp/terraform","slug":"failed-to-retrieve-workspace-s-v-e485a2","errorCode":null,"errorMessage":"failed to retrieve workspace %s: %v","messagePattern":"failed to retrieve workspace (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/backend.go","lineNumber":716,"sourceCode":"// DeleteWorkspace implements backend.Backend (which is embedded in backendrun.OperationsBackend).\nfunc (b *Cloud) DeleteWorkspace(name string, force bool) tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\n\tif name == backend.DefaultStateName {\n\t\treturn diags.Append(backend.ErrDefaultWorkspaceNotSupported)\n\t}\n\n\tif b.WorkspaceMapping.Strategy() == WorkspaceNameStrategy {\n\t\treturn diags.Append(backend.ErrWorkspacesNotSupported)\n\t}\n\n\tworkspace, err := b.client.Workspaces.Read(context.Background(), b.Organization, name)\n\tif err == tfe.ErrResourceNotFound {\n\t\treturn nil // If the workspace does not exist, succeed\n\t}\n\n\tif err != nil {\n\t\treturn diags.Append(fmt.Errorf(\"failed to retrieve workspace %s: %v\", name, err))\n\t}\n\n\t// Configure the remote workspace name.\n\tState := &State{tfeClient: b.client, organization: b.Organization, workspace: workspace, enableIntermediateSnapshots: false}\n\treturn diags.Append(State.Delete(force))\n}\n\n// StateMgr implements backend.Backend (which is embedded in backendrun.OperationsBackend).\nfunc (b *Cloud) StateMgr(name string) (statemgr.Full, tfdiags.Diagnostics) {\n\tvar diags tfdiags.Diagnostics\n\n\tvar remoteTFVersion string\n\n\tif name == backend.DefaultStateName {\n\t\treturn nil, diags.Append(backend.ErrDefaultWorkspaceNotSupported)\n\t}\n\n\tif b.WorkspaceMapping.Strategy() == WorkspaceNameStrategy && name != b.WorkspaceMapping.Name {","sourceCodeStart":698,"sourceCodeEnd":734,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/backend.go#L698-L734","documentation":"Returned in backend DeleteWorkspace at backend.go:716 when b.client.Workspaces.Read returns a non-ErrResourceNotFound error during terraform workspace delete. NotFound is treated as success (idempotent delete); any other error (permissions, API failure, network) is reported here with %s=workspace name and %v=error.","triggerScenarios":"terraform workspace delete <name> against a cloud backend; the workspace Read call fails with an error other than 404.","commonSituations":"Token lacks workspace read/delete permission; API outage; rate limiting; workspace name typo that surfaces as a permission or transport error rather than 404.","solutions":["Ensure the token's team has admin/delete permission on the workspace.","Retry after transient API errors; verify HCP/TFE status page.","Confirm the workspace name is correct and not locked by a run."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-check workspace existence for delete to give a clearer error.\nif _, err := b.client.Workspaces.Read(ctx, org, name); err != nil && !errors.Is(err, tfe.ErrResourceNotFound) {\n    return fmt.Errorf(\"cannot verify workspace %s: %w\", name, err)\n}","typeGuard":"if errors.Is(err, tfe.ErrResourceNotFound) { return nil /* idempotent */ }","tryCatchPattern":"ws, err := b.client.Workspaces.Read(ctx, org, name)\nif errors.Is(err, tfe.ErrResourceNotFound) {\n    return nil // already gone\n} else if err != nil {\n    return fmt.Errorf(\"failed to retrieve workspace %s: %v\", name, err)\n}","preventionTips":["Grant workspace admin/delete permission to the token's team.","Ensure the workspace is not locked by an active run before deleting."],"tags":["terraform","cloud-backend","tfe-api","workspaces","delete"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}