hashicorp/terraform · error
empty state name
Error message
empty state name
What it means
Returned by Local.DeleteWorkspace (internal/backend/local/backend.go:244) when the provided workspace name is the empty string. The local backend refuses to delete a workspace with no name because there is nothing to target and it would be a programming error rather than a user action.
Source
Thrown at internal/backend/local/backend.go:244
sort.Strings(listed)
envs = append(envs, listed...)
return envs, diags
}
// DeleteWorkspace removes a workspace.
//
// The "default" workspace cannot be removed.
func (b *Local) DeleteWorkspace(name string, force bool) tfdiags.Diagnostics {
var diags tfdiags.Diagnostics
// If we have a backend handling state, defer to that.
if b.Backend != nil {
return b.Backend.DeleteWorkspace(name, force)
}
if name == "" {
return diags.Append(errors.New("empty state name"))
}
if name == backend.DefaultStateName {
return diags.Append(errors.New("cannot delete default state"))
}
delete(b.states, name)
err := os.RemoveAll(filepath.Join(b.stateWorkspaceDir(), name))
if err != nil {
return diags.Append(fmt.Errorf("error deleting workspace %s: %w", name, err))
}
return diags
}
func (b *Local) StateMgr(name string) (statemgr.Full, tfdiags.Diagnostics) {
var diags tfdiags.Diagnostics
View on GitHub (pinned to c9def3e214)
Solutions
- Resolve and pass a non-empty workspace name to DeleteWorkspace.
- Validate that the workspace name is non-empty before calling the API (guard at the call site).
- If the empty name comes from env/config, fix the configuration so the workspace is always defined.
Example fix
// before
b.DeleteWorkspace(ws, false) // ws may be ""
// after
if ws == "" {
return fmt.Errorf("cannot delete workspace: name is empty")
}
b.DeleteWorkspace(ws, false) Defensive patterns
Strategy: validation
Validate before calling
if name == "" {
return fmt.Errorf("cannot delete workspace: name is empty")
}
b.DeleteWorkspace(name, force) Prevention
- Always validate the workspace name is non-empty before calling DeleteWorkspace.
- Resolve the current workspace from config/env at a single chokepoint rather than at each call site.
- Default unresolved workspace values to backend.DefaultStateName.
When it happens
Trigger: Calling (*Local).DeleteWorkspace("", force) directly; CLI/frontend code that passes an unset/empty workspace variable (e.g. a missing TF_WORKSPACE or an unconfigured current workspace) into DeleteWorkspace.
Common situations: Bugs in wrappers/automation that fail to resolve the current workspace before calling DeleteWorkspace; scripts that read the workspace from a config/env var that was never set and pass the zero value.
Related errors
- cannot delete default state
- missing state name
- missing state name
- missing state name
- default workspace not supported You can create a new workspa
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/be354295f38283c2.
Report an issue: GitHub.