terraform-workspace
Create, select, and delete Terraform workspaces
TLDR
SYNOPSIS
terraform workspace list | show | new [options] NAME | select [options] NAME | delete [options] NAME
DESCRIPTION
terraform workspace manages workspaces: separate state instances that share one configuration. It is a terraform command group, not a separate binary. Each subcommand has its own options. A new working directory starts in the default workspace.list and show only read the local workspace index. select changes which state later commands such as plan and apply will use. new creates a workspace and selects it. select -or-create is the form to use in scripts that should succeed whether or not the name already exists.delete refuses a workspace whose state still contains resources, unless -force is set. Forcing the delete removes the state. It does not destroy the real infrastructure those objects represent.
PARAMETERS
list
Print every workspace in this working directory. The selected workspace is markedshow
Print only the name of the selected workspacenew NAME
Create NAME and select it. -state path copies an existing state file into the new workspace instead of starting emptyselect NAME
Select an existing workspace. -or-create creates NAME when it does not exist yetdelete NAME
Delete NAME. -force deletes it even when its state still tracks resources-lock true|false
Lock state during new, select, and delete. The default is to lock-lock-timeout duration
How long to wait for the state lock. The default is `0s`
INSTALL
CAVEATS
You cannot delete the workspace that is currently selected. Select another one first. The default workspace cannot be deleted.-force drops state that still names real objects. Those objects keep running. Destroy them with terraform destroy in that workspace before deleting it, unless you intend to abandon the state on purpose.Workspaces are not a substitute for separate root modules when the configurations themselves should differ. They separate state, not the `.tf` files.
HISTORY
Terraform gained named environments early, and those were renamed workspaces. select -or-create is the later flag for creating a missing workspace in one step. Terraform itself was created by Mitchell Hashimoto at HashiCorp and first released in 2014.
SEE ALSO
terraform(1), terraform-init(1), terraform-plan(1)
