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

  1. Write — describe your desired infrastructure in .tf files.
  2. Plan — run terraform plan to preview exactly what will be created, changed, or destroyed.
  3. Apply — run terraform apply to make the changes real.

When you no longer need the infrastructure, terraform destroy tears it all down.

The Terraform workflow: write then plan then apply, with destroy to tear downWritePlanApplyDestroyedit and repeat
Write, preview with plan, make real with apply. Loop as your needs change.

Example

Example Β· bash
# 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 destroy

When 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.

Example Β· bash
# 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 apply

Save and use a plan file

Saves a plan to disk so the exact same diff that was reviewed is what gets applied, preventing surprises.

Example Β· bash
# 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 tfplan

Destroy resources cleanly

Demonstrates previewing and executing destruction of managed resources, including targeting a single resource.

Example Β· bash
# 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

  • Be the first to comment on this lesson.
The Terraform Workflow β€” Terraform | SoundsCode