Free course · 11 lessons · Advanced

Terraform in Production

Running Terraform safely with a team: locked remote state on AWS, Azure and GCP, secrets kept out of state, drift detection, count vs for_each, refactoring with moved, removed and import blocks, guard rails for destructive plans, applying the reviewed plan, pinning providers and modules, and splitting state to limit blast radius, with real Terraform plans and runnable simulations in every lesson.

Start the course

1. State You Can Trust

Terraform state is a shared database of what exists. Lock it, keep secrets out of it, and notice when reality drifts away from it.

  1. Two Applies, One State File — Why concurrent applies lose resources from state, and how remote backends with locking stop it on AWS, Azure and GCP.
  2. Secrets in State — sensitive = true hides values from the console, not from state. Keep secrets out of state, and treat state as a secret.
  3. Drift: When Reality Changes Behind Terraform — Console hot-fixes and other tools change real resources. Detect drift on a schedule and decide whether to adopt or revert it.

2. Changes That Don't Destroy Things

Most Terraform outages are a plan that replaced or deleted something nobody meant to touch. Learn to read, shape and guard plans.

  1. Removing One Tenant Recreated Another — count addresses resources by position, so removing an item from the middle of a list shifts every index after it. for_each uses stable keys.
  2. Refactoring Without Recreating Everything — Renaming a resource or moving it into a module changes its address. moved, removed and import blocks keep real infrastructure untouched.
  3. Guard Rails for Destructive Plans — prevent_destroy, deletion protection and an automated plan check together stop a bad plan from deleting stateful resources.

3. Pipelines and Scale

Apply exactly what was reviewed, pin what you depend on, and split state so one change can't take down everything.

  1. Apply Exactly What Was Reviewed — A plan in the PR and a fresh apply on merge are two different plans. Save the plan, apply that file, and let stale plans fail.
  2. The Unpinned Module That Broke Prod — Unpinned modules and loose provider constraints change under you. Pin versions, commit the lock file and upgrade on purpose.
  3. Blast Radius: Splitting a Monolithic State — One state for everything makes every plan slow and every mistake global. Split by lifecycle and ownership, and connect stacks through published outputs.

4. Capstone Case Studies

Design a production Terraform setup for a growing company, and investigate an incident caused by a plan that deleted a queue.

  1. Capstone: A Production Terraform Setup for a Growing Company — Twelve engineers, three environments and two clouds on the horizon. Design how they write, review and apply Terraform safely.
  2. Capstone: Postmortem — The Plan That Deleted a Queue — Reconstruct an incident from a plan, a pipeline and a timeline; find the root causes and write the remediation plan.