{"record":{"id":"b3d02a3bdf066ace","repo":"hashicorp/terraform","slug":"can-t-delete-default-state","errorCode":null,"errorMessage":"can't delete default state","messagePattern":"can't delete default state","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/backend/remote-state/azure/backend_state.go","lineNumber":70,"sourceCode":"\t\t\t}\n\n\t\t\tenvs[name] = struct{}{}\n\t\t}\n\t}\n\n\tresult := []string{backend.DefaultStateName}\n\tfor name := range envs {\n\t\tresult = append(result, name)\n\t}\n\tsort.Strings(result[1:])\n\treturn result, diags\n}\n\nfunc (b *Backend) DeleteWorkspace(name string, _ bool) tfdiags.Diagnostics {\n\tvar diags tfdiags.Diagnostics\n\n\tif name == backend.DefaultStateName || name == \"\" {\n\t\treturn diags.Append(fmt.Errorf(\"can't delete default state\"))\n\t}\n\n\tctx := newCtx()\n\tclient, err := b.apiClient.getBlobClient(ctx)\n\tif err != nil {\n\t\treturn diags.Append(err)\n\t}\n\n\tif resp, err := client.Delete(ctx, b.containerName, b.path(name), blobs.DeleteInput{}); err != nil {\n\t\tif !response.WasNotFound(resp.HttpResponse) {\n\t\t\treturn diags.Append(err)\n\t\t}\n\t}\n\n\treturn diags\n}\n\nfunc (b *Backend) StateMgr(name string) (statemgr.Full, tfdiags.Diagnostics) {","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/backend/remote-state/azure/backend_state.go#L52-L88","documentation":"Returned by DeleteWorkspace when the requested name is the default workspace (\"default\") or empty. The default workspace holds the canonical state and cannot be removed via the workspace-delete API. This is a deliberate invariant, not a transient failure.","triggerScenarios":"User runs `terraform workspace delete default` (or empty name), or a script enumerates and deletes all workspaces including the default.","commonSituations":"CI cleanup scripts that loop over `terraform workspace list` and call delete on each; user confusion about workspace lifecycle.","solutions":["Skip the default workspace in any bulk-delete script (filter out \"default\").","If you must start fresh, delete the state blob manually via Azure CLI / portal rather than via workspace delete.","Use a non-default workspace name for ephemeral environments."],"exampleFix":"// before\nfor ws in $(terraform workspace list); do terraform workspace delete $ws; done\n// after\nfor ws in $(terraform workspace list | grep -v default); do terraform workspace delete $ws; done","handlingStrategy":"validation","validationCode":"// Validate workspace name before calling DeleteWorkspace.\nfunc validateWorkspaceDeletable(name string) error {\n    if name == \"\" || name == backend.DefaultStateName {\n        return fmt.Errorf(\"can't delete default state\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter 'default' out of any bulk workspace-delete script.","Use ephemeral non-default workspaces for CI environments.","If the goal is to reset state, delete the state blob via Azure CLI rather than workspace delete."],"tags":["azure","workspace","validation","invariant"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}