LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

terraform-workspace

Create, select, and delete Terraform workspaces

TLDR

List workspaces (the current one is marked)
$ terraform workspace list
copy
Print the current workspace name
$ terraform workspace show
copy
Create a workspace
$ terraform workspace new [name]
copy
Select an existing workspace
$ terraform workspace select [name]
copy
Select a workspace, creating it if needed
$ terraform workspace select -or-create [name]
copy
Delete a workspace that is not tracking resources
$ terraform workspace delete [name]
copy
Delete a workspace even if it has resources
$ terraform workspace delete -force [name]
copy

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 marked
show
Print only the name of the selected workspace
new NAME
Create NAME and select it. -state path copies an existing state file into the new workspace instead of starting empty
select NAME
Select an existing workspace. -or-create creates NAME when it does not exist yet
delete 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

sudo pacman -S terraform
copy
nix profile install nixpkgs#terraform
copy

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

RESOURCES

Copied to clipboard
Kai