Terraform Cheatsheet
Quick reference for Terraform CLI commands covering init, plan, apply, state management, workspaces, import, output, and formatting
57 commands
terraform initInitialize working directory
terraform initterraform init -upgradeInitialize and upgrade providers
terraform init -upgradeterraform init -backend-configInitialize with backend config
terraform init -backend-config=backend.hclterraform init -migrate-stateInitialize with state migration
terraform init -migrate-stateterraform init -reconfigureReconfigure backend during init
terraform init -reconfigureterraform providersShow required providers
terraform providersterraform providers lockUpdate provider lock file
terraform providers lock -platform=linux_amd64terraform versionShow Terraform version
terraform versionterraform planShow execution plan
terraform planterraform plan -outSave execution plan to file
terraform plan -out=tfplanterraform plan -varPlan with variable
terraform plan -var='region=us-east-1'terraform plan -var-filePlan with variable file
terraform plan -var-file=prod.tfvarsterraform plan -targetPlan for specific resource only
terraform plan -target=aws_instance.webterraform plan -destroyShow destroy plan
terraform plan -destroyterraform applyApply changes
terraform applyterraform apply -auto-approveApply without confirmation
terraform apply -auto-approveterraform apply tfplanApply saved plan
terraform apply tfplanterraform destroyDestroy all managed resources
terraform destroyterraform destroy -targetDestroy specific resource
terraform destroy -target=aws_instance.webterraform refreshSync state with actual resources
terraform refreshterraform state listList resources in state
terraform state listterraform state showShow resource details in state
terraform state show aws_instance.webterraform state mvMove/rename resource in state
terraform state mv aws_instance.old aws_instance.newterraform state rmRemove resource from state
terraform state rm aws_instance.webterraform state pullPull remote state
terraform state pullterraform state pushPush local state to remote
terraform state push terraform.tfstateterraform state replace-providerReplace provider in state
terraform state replace-provider hashicorp/aws registry.example.com/awsterraform force-unlockForce unlock state
terraform force-unlock LOCK_IDterraform workspace listList workspaces
terraform workspace listterraform workspace newCreate new workspace
terraform workspace new stagingterraform workspace selectSwitch workspace
terraform workspace select productionterraform workspace showShow current workspace
terraform workspace showterraform workspace deleteDelete workspace
terraform workspace delete stagingterraform importImport existing resource to state
terraform import aws_instance.web i-1234567890terraform import (module)Import resource into module
terraform import module.vpc.aws_vpc.main vpc-abc123terraform import (for_each)Import for_each resource
terraform import 'aws_iam_user.users["admin"]' adminterraform import (count)Import count resource
terraform import 'aws_instance.servers[0]' i-1234567890terraform plan -generate-config-outGenerate config during import
terraform plan -generate-config-out=generated.tfterraform outputShow all output values
terraform outputterraform output (name)Show specific output value
terraform output instance_ipterraform output -jsonShow outputs in JSON format
terraform output -jsonterraform output -rawShow raw output value
terraform output -raw instance_ipterraform consoleStart interactive console
terraform consoleterraform graphGenerate resource dependency graph
terraform graph | dot -Tpng > graph.pngterraform showShow state or plan in readable format
terraform showterraform show -jsonShow state in JSON format
terraform show -jsonterraform getDownload modules
terraform getterraform get -updateUpdate modules to latest
terraform get -updateterraform init (module source)Get module from Git repository
terraform initterraform testRun Terraform tests
terraform testterraform providers mirrorMirror providers to local directory
terraform providers mirror /path/to/mirrorterraform fmtFormat configuration files
terraform fmtterraform fmt -checkCheck formatting without changes
terraform fmt -checkterraform fmt -recursiveFormat recursively
terraform fmt -recursiveterraform validateValidate configuration syntax
terraform validateterraform fmt -diffShow format diff
terraform fmt -diffterraform loginLog in to Terraform Cloud
terraform login