The Terraform Workflow
The core loop is Write, Plan, Apply: author config, preview changes, then make them real.
Almost everything you do with Terraform follows the same three-step loop.
Write → Plan → Apply
- Write — describe your desired infrastructure in
.tffiles. - Plan — run
terraform planto preview exactly what will be created, changed, or destroyed. - Apply — run
terraform applyto make the changes real.
When you no longer need the infrastructure, terraform destroy tears it all down.
Example
# 1. Initialize the working directory (download providers)
terraform init
# 2. Preview the changes Terraform will make
terraform plan
# 3. Apply the changes to real infrastructure
terraform apply
# 4. Tear everything down when finished
terraform destroyWhen to use it
- A developer writes a new EC2 resource block, runs terraform plan to review the proposed changes, then runs terraform apply to create it.
- A team uses the Write-Plan-Apply loop in CI: the plan output is posted as a pull-request comment for human review before merging triggers apply.
- An operator runs terraform destroy at the end of a feature branch lifecycle to tear down temporary cloud resources and avoid runaway costs.
More examples
Full Write-Plan-Apply loop
Shows the three-step core workflow every Terraform operator follows before touching production infrastructure.
# 1. Write: create or edit .tf files
vim main.tf
# 2. Plan: preview what will change
terraform plan
# 3. Apply: make the changes real
terraform applySave and use a plan file
Saves a plan to disk so the exact same diff that was reviewed is what gets applied, preventing surprises.
# Save the plan to a binary file
terraform plan -out=tfplan
# Inspect it as JSON
terraform show -json tfplan | jq '.resource_changes[].change.actions'
# Apply exactly that saved plan (no prompt)
terraform apply tfplanDestroy resources cleanly
Demonstrates previewing and executing destruction of managed resources, including targeting a single resource.
# Preview what destroy will remove
terraform plan -destroy
# Destroy all managed resources
terraform destroy
# Or target just one resource
terraform destroy -target=aws_instance.web
Discussion