← Cheatsheets
IaC

Terraform

Core Terraform commands for provisioning infrastructure, managing state and working with workspaces.

Init & Setup

terraform init
terraform init -upgrade
terraform providers
terraform version
terraform fmt
terraform fmt -recursive
terraform validate

Plan & Apply

terraform plan
terraform plan -out=tfplan
terraform plan -var 'key=value'
terraform plan -var-file=prod.tfvars
terraform apply
terraform apply tfplan
terraform apply -auto-approve
terraform apply -target=<resource>
terraform refresh

State Management

terraform state list
terraform state show <resource>
terraform state pull
terraform state push <file>
terraform state mv <src> <dst>
terraform state rm <resource>

Import & Move

terraform import <resource> <id>
terraform moved { from = ... to = ... }

Workspaces

terraform workspace list
terraform workspace show
terraform workspace new <name>
terraform workspace select <name>
terraform workspace delete <name>

Destroy

terraform destroy
terraform destroy -target=<resource>
terraform destroy -auto-approve
terraform plan -destroy

Output & Inspection

terraform output
terraform output <name>
terraform output -json
terraform graph | dot -Tsvg > graph.svg
terraform console