terraform workspace select
Theterraform workspace select command switches to a different workspace.
Usage
Description
This command switches the currently active workspace to the workspace specified byNAME. The workspace must already exist unless the -or-create flag is used.
Switching workspaces changes which state file Terraform uses for subsequent operations. Each workspace maintains its own state, allowing you to manage multiple environments or configurations from the same Terraform code.
Arguments
NAME- (Required) The name of the workspace to select. Must be a valid workspace name containing only URL-safe characters with no path separators.
Options
-or-create- If the specified workspace doesn’t exist, create it before selecting it. Default:false
Examples
Switch to an Existing Workspace
Create and Switch to a New Workspace
Behavior Notes
Workspace Override
You cannot useterraform workspace select when the TF_WORKSPACE environment variable is set. If you attempt to do so, the command will fail with:
Selecting Current Workspace
If you select the workspace that is already active, the command succeeds immediately without making any changes.Non-existent Workspace
If you attempt to select a workspace that doesn’t exist (without using-or-create), the command will fail:
Exit Codes
0- Success1- Error (e.g., workspace doesn’t exist, backend failed to load, workspace name is invalid, TF_WORKSPACE is set)
Related Commands
- terraform workspace list - List all workspaces
- terraform workspace new - Create a new workspace
- terraform workspace show - Show the current workspace name
- terraform workspace delete - Delete a workspace