Documentation Index
Fetch the complete documentation index at: https://mintlify.com/hashicorp/terraform/llms.txt
Use this file to discover all available pages before exploring further.
terraform workspace delete
Theterraform workspace delete command deletes a workspace.
Usage
Description
This command deletes the specified workspace and its associated state. By default, Terraform prevents deletion of workspaces that contain managed resources to protect against accidental data loss.Arguments
NAME- (Required) The name of the workspace to delete. Cannot be empty.
Options
-
-force- Remove a workspace even if it contains managed resources. Use with extreme caution. Default:false -
-lock=true- Lock the state file during the operation. Set tofalseto disable locking. Default:true -
-lock-timeout=0s- Duration to wait for a state lock to be released before timing out. Accepts values like10sor5m. Default:0s(no retry)
Examples
Delete an Empty Workspace
Force Delete a Non-Empty Workspace
Delete with Lock Timeout
Behavior Notes
Non-Empty Workspace Protection
If a workspace contains managed resources and you don’t use the-force flag, the command will fail with a detailed error listing all managed resources:
Cannot Delete Current Workspace
You cannot delete the workspace that is currently selected. Switch to another workspace first:Cannot Delete Default Workspace
Thedefault workspace cannot be deleted:
Non-Existent Workspace
If you attempt to delete a workspace that doesn’t exist, the command will fail:Empty String Name
You cannot delete a workspace with an empty string as the name:Best Practices
-
Destroy resources first: Always run
terraform destroybefore deleting a workspace to properly clean up infrastructure. -
Verify workspace contents: Use
terraform state listto check what resources are managed before deletion. -
Avoid
-forcein automation: The-forceflag should only be used when you’re certain about the consequences.
Exit Codes
0- Success1- Error (e.g., workspace doesn’t exist, workspace is current, workspace contains resources, workspace is default, failed to load backend)
Related Commands
- terraform workspace list - List all workspaces
- terraform workspace select - Switch to a different workspace
- terraform workspace show - Show the current workspace name
- terraform workspace new - Create a new workspace
- terraform destroy - Destroy infrastructure before deleting a workspace