Terraform Infrastructure as code
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
terraform initterraform fmtterraform validate
terraform plan -out=<file>
terraform apply <file>
terraform output
terraform state list
terraform destroy
Concepts
- Config .tf files
- Working dir providers, modules
- Plan diff vs. state
- Infrastructure state updated
Workflow
terraform initterraform init -upgrade
terraform init -reconfigure
terraform init -migrate-state
terraform validate
terraform planterraform plan -out=<file>
terraform applyterraform apply <planfile>
terraform apply -auto-approve
terraform destroy
terraform plan -destroy
terraform apply -refresh-only
terraform fmtterraform fmt -recursive -check
Targeting & plans
terraform plan -target=<addr>
terraform apply -replace=<addr>
terraform plan -refresh=false
terraform plan -parallelism=<n>
terraform plan -detailed-exitcode
terraform show <planfile>
terraform show -json <planfile>
terraform graphVariables & outputs
terraform plan -var
'<name>=<value>'
terraform plan -var-file=<file>
TF_VAR_<name>=<value>
terraform.tfvars
terraform output
terraform output <name>
terraform output -raw <name>
terraform output -json
terraform console
State
terraform state list
terraform state show <addr>
terraform state mv <src> <dst>
terraform state rm <addr>
terraform state pull
terraform state push <file>
terraform import <addr> <id>
terraform taint <addr>
terraform untaint <addr>
terraform force-unlock <id>
terraform refresh
Workspaces
terraform workspace list
terraform workspace show
terraform workspace new <name>
terraform workspace select <name>
terraform workspace delete <name>
Providers & modules
terraform providers
terraform providers lock
terraform getterraform modules
terraform version
terraform loginterraform -chdir=<dir> <cmd>
Recipes
terraform initterraform fmt -checkterraform validateterraform plan -out=tfplanterraform apply tfplan
terraform workspace select prodterraform plan -var-file=prod.tfvars -out=tfplanterraform apply tfplan
terraform state mv aws_instance.old aws_instance.new# update the resource name in the .tf fileterraform plan # expect no changes
terraform plan -replace=aws_instance.webterraform apply -replace=aws_instance.web



