Core Workflow

terraform init Initialize working directory
terraform plan Preview changes
terraform apply Apply changes
terraform apply -auto-approve Apply without prompt
terraform destroy Destroy infrastructure
terraform destroy -auto-approve Destroy without prompt

Planning

terraform plan -out=plan.tfplan Save plan to file
terraform apply plan.tfplan Apply saved plan
terraform plan -target=aws_instance.web Target specific resource
terraform plan -var="env=prod" Pass variable
terraform plan -var-file="prod.tfvars" Use variable file
terraform plan -refresh=false Skip refresh
terraform plan -parallelism=10 Parallel operations

State Management

terraform state list List resources in state
terraform state show aws_instance.web Show resource details
terraform state mv old_name new_name Rename resource
terraform state rm aws_instance.web Remove from state
terraform state pull Pull remote state
terraform state push Push state to remote
terraform refresh Update state
terraform import aws_instance.web i-1234567 Import existing resource

Workspace

terraform workspace list List workspaces
terraform workspace new dev Create workspace
terraform workspace select prod Switch workspace
terraform workspace show Show current workspace
terraform workspace delete dev Delete workspace

Validation & Formatting

terraform validate Validate configuration
terraform fmt Format code
terraform fmt -check Check formatting
terraform fmt -recursive Format recursively
terraform fmt -diff Show formatting diff

Output & Debug

terraform output Show all outputs
terraform output instance_ip Show specific output
terraform output -json JSON format
terraform console Interactive console
terraform graph | dot -Tpng > graph.png Generate graph
TF_LOG=DEBUG terraform plan Enable debug logging
TF_LOG_PATH=./tf.log terraform plan Log to file

Providers & Modules

terraform providers List providers
terraform providers lock Lock provider versions
terraform get Download modules
terraform get -update Update modules
terraform init -upgrade Upgrade providers

Taint & Replace

terraform taint aws_instance.web Mark for recreation (deprecated)
terraform untaint aws_instance.web Unmark resource
terraform apply -replace=aws_instance.web Replace resource

Backend Configuration

terraform init -backend-config="bucket=tfstate" Override backend config
terraform init -reconfigure Reconfigure backend
terraform init -migrate-state Migrate state to new backend
terraform force-unlock LOCK_ID Release state lock