Workspace Commands
Imagine you’ve got multiple drawers in your Lego city blueprint cabinet - one for dev, one for staging, and one for prod. Workspaces are those drawers, and Terraform gives you a set of commands to create, switch, and manage them. Mastering these commands ensures you can move smoothly between environments without mixing up their state files.
Key Commands
1. Create a New Workspace
- Creates a new workspace called
dev. - Initializes a separate state file for that workspace.
terraform workspace new dev
2. Switch Between Workspaces
- Switches to the
prodworkspace. - Ensures subsequent
planandapplycommands use theprodstate.
terraform workspace select prod
3. List All Workspaces
- Displays all available workspaces.
- Current workspace is marked with an asterisk
*.
terraform workspace list
4. Show Current Workspace
- Prints the name of the active workspace.
- Useful for confirming which environment you’re working in.
terraform workspace show
5. Delete a Workspace
- Removes the
devworkspace (only if its state is empty). - Prevents clutter from unused environments.
terraform workspace delete dev
Hands‑On Lab / Demo
Lab: Managing Workspaces
Show current workspace:
terraform workspace show
→ Output: staging
List all workspaces:
terraform workspace list
# → Output:
default
dev
* staging
prodSwitch to it:
terraform workspace select staging
Create a new workspace:
terraform workspace new staging
Pro Tips & Best Practices
- Always confirm your current workspace before running
apply. - Use consistent naming (
dev,staging,prod). - Avoid deleting workspaces with active state.
- Document workspace usage in project README.
- For large teams, consider remote backends with workspace support.
Summary & Cheatsheet
- Create:
terraform workspace new <name> - Switch:
terraform workspace select <name> - List:
terraform workspace list - Show current:
terraform workspace show - Delete:
terraform workspace delete <name>
Quick mnemonic: New, Select, List, Show, Delete = NSLSD
The Hackers Notebook
Workspace commands are the navigation tools of Terraform environments. They let you create, switch, and manage isolated states without duplicating code. By mastering these commands, you ensure smooth transitions between dev, staging, and prod.

Updated on Dec 28, 2025