List workspaces
Show available Terraform CLI workspaces for the current configuration.
terraform workspace listShow available Terraform CLI workspaces for the current configuration.
Manage Terraform CLI workspaces, local and remote state, imports, and state surgery commands.
Create, list, switch, and delete CLI workspaces.
Show available Terraform CLI workspaces for the current configuration.
terraform workspace listShow available Terraform CLI workspaces for the current configuration.
Print the current Terraform CLI workspace name.
terraform workspace showPrint the current Terraform CLI workspace name.
terraform workspace new devCreate and switch to a new workspace.
terraform workspace select prodSwitch to an existing workspace.
terraform workspace delete devDelete a Terraform CLI workspace.
Bring existing infra under management and modify state safely.
Associate an existing infrastructure object with a resource address in state.
terraform import aws_s3_bucket.logs my-logs-bucketAssociate an existing infrastructure object with a resource address in state.
Generate configuration while importing supported resources.
terraform import -generate-config-out=generated.tf aws_s3_bucket.logs my-logs-bucketGenerate configuration while importing supported resources.
terraform state mv aws_instance.old aws_instance.newRename or move a resource address in state.
Stop tracking a resource without destroying the remote object.
terraform state rm aws_instance.webStop tracking a resource without destroying the remote object.
Update provider source addresses recorded in state.
terraform state replace-provider hashicorp/aws registry.acme.corp/acme/awsUpdate provider source addresses recorded in state.
Read and write raw state when needed.
Download the latest state and write it to a local file.
terraform state pull > terraform.tfstateDownload the latest state and write it to a local file.
Upload a local state file into the configured backend.
terraform state push terraform.tfstateUpload a local state file into the configured backend.
List resources beneath a specific module path.
terraform state list module.networkList resources beneath a specific module path.
Reconfigure backend and migrate state between backends.
Move state to a newly configured backend during re-init.
terraform init -migrate-stateMove state to a newly configured backend during re-init.
Automatically copy existing state to a new backend without prompting.
terraform init -force-copyAutomatically copy existing state to a new backend without prompting.
Use providers from the dependency lock file without updating it.
terraform init -lockfile=readonlyUse providers from the dependency lock file without updating it.
Useful snippets for remote and local state workflows.
Use a non-default local state path for commands that support it.
terraform plan -state=terraform.tfstateUse a non-default local state path for commands that support it.
Exclude paths from uploaded configuration when using remote CLI-driven runs.
.terraformignore
.git/
.terraform/
node_modules/
*.pemExclude paths from uploaded configuration when using remote CLI-driven runs.
Example backend configuration for HCP Terraform remote state and runs.
terraform {
backend "remote" {
organization = "acme"
workspaces {
name = "networking-prod"
}
}
}Example backend configuration for HCP Terraform remote state and runs.