Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Terraform, Ansible & IaCVisual series

The Terraform command cheat sheet

The plan says three to add, none to change and one to destroy, and everyone scrolls to the bottom. Terraform is four verbs and twenty commands, and the state file decides whether you sleep.

Quick reference

Init

terraform init
terraform init -upgrade
terraform init -reconfigure
terraform providers
terraform version

Plan

terraform plan -out=tfplan
terraform plan -var-file=prod.tfvars
terraform show -no-color tfplan
terraform validate
terraform fmt -check -recursive

State

terraform state list
terraform state show aws_instance.api
terraform state pull
terraform state mv module.old module.new
terraform apply -refresh-only

Import

terraform import aws_s3_bucket.logs logs
terraform plan -generate-config-out=gen.tf
terraform state list | grep logs
terraform plan -target=aws_s3_bucket.logs
terraform state rm aws_s3_bucket.logs

Explained

Init

Init prepares the directory: downloads providers, writes the lock file. -upgrade moves to the newest allowed versions, -reconfigure forgets a moved backend. terraform providers lists what is installed, and terraform version names the binary.

Plan

Plan shows what would change. -out=tfplan records the decision for the apply, -var-file picks production values. show -no-color prints it for a pull request, validate catches type errors, and fmt -check -recursive fails CI on unformatted files.

State

State maps configuration to real resources. state list names the addresses, state show reads one, state pull prints the file. state mv moves an address without touching the cloud, and apply -refresh-only updates state from reality without changing infrastructure.

Import

Import adopts what already exists. terraform import aws_s3_bucket.logs logs writes it into state, plan -generate-config-out=gen.tf writes matching HCL, state list | grep logs confirms it, and state rm drops it from state without deleting the bucket.

The honest caveat: -target is for recovery, not routine work. A targeted plan ignores everything outside the target, so a green run says little about the whole configuration.

The lesson: the plan is the review and the state is the database. Treat both with the care that implies.

In one line

Plan first. Then apply. The plan is the review; the state is the database.

Review the plan

terraform show -no-color tfplan

More notes: Terraform, Ansible & IaC

Open in the notes app: search, filters, copy This note on GitHub