hashicorp/terraform · warning
can't delete default state
Error message
can't delete default state
What it means
The Kubernetes backend refuses to delete its default workspace. DeleteWorkspace() rejects the name 'default' and the empty string at backend_state.go:72-74, mirroring other backends, because the default workspace is always present and cannot be removed.
Source
Thrown at internal/backend/remote-state/kubernetes/backend_state.go:73
// Make sure it isn't default and the key matches
if ws != backend.DefaultStateName && key == b.nameSuffix {
m[ws] = struct{}{}
}
}
states := []string{backend.DefaultStateName}
for k := range m {
states = append(states, k)
}
sort.Strings(states[1:])
return states, diags
}
func (b *Backend) DeleteWorkspace(name string, _ bool) tfdiags.Diagnostics {
var diags tfdiags.Diagnostics
if name == backend.DefaultStateName || name == "" {
return diags.Append(fmt.Errorf("can't delete default state"))
}
client, err := b.remoteClient(name)
if err != nil {
return diags.Append(err)
}
return diags.Append(client.Delete())
}
func (b *Backend) StateMgr(name string) (statemgr.Full, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
c, err := b.remoteClient(name)
if err != nil {
return nil, diags.Append(err)
}
View on GitHub (pinned to c9def3e214)
Solutions
- Exclude the 'default' workspace from any deletion loop.
- Delete only named non-default workspaces; the default is immutable in this respect.
- If you need to clear default state, use `terraform state` subcommands or delete the underlying Secret manually (risk: orphaned lease).
Example fix
# before - attempts to delete the protected default workspace terraform workspace delete default # after - delete a non-default workspace instead terraform workspace select default terraform workspace delete my-feature-env
Defensive patterns
Strategy: validation
Validate before calling
// Skip the protected default workspace in any k8s backend deletion routine
for _, ws := range workspaces {
if ws == backend.DefaultStateName || ws == "" {
continue
}
_ = b.DeleteWorkspace(ws, false)
} Prevention
- Never target 'default' in workspace deletion automation.
- Document that the default workspace is immutable for deletion.
- Clear default state via state subcommands rather than workspace deletion.
When it happens
Trigger: Running `terraform workspace delete default` while using the kubernetes backend, which calls DeleteWorkspace at backend_state.go:70-82.
Common situations: Workspace cleanup automation that enumerates and deletes all workspaces without excluding 'default'; CI teardown scripts that iterate `terraform workspace list`.
Related errors
- can't delete default state
- Failed to configure: %s
- secret_suffix must not end with '-<number>', got %q
- Failed to initialize kubernetes configuration: %s
- %v Additionally, unlocking the state in Kubernetes faile
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/8eb555a29f461e66.
Report an issue: GitHub.