Course contentsShow
← Cloud and Infrastructure
Lesson 771 of 2,98914. Terraform FundamentalsFree lesson

terraform plan Explained

How terraform plan generates an execution plan by comparing desired state to current infrastructure state.

terraform plan Explained

What you'll learn: How terraform plan compares your desired infrastructure configuration with the current real-world state to generate a safe, previewable execution plan.

What Does terraform plan Do?

Think of terraform plan as a "dress rehearsal" before the actual performance. Before making any changes to your cloud infrastructure, Terraform reads your configuration files (what you want), checks the current state of your real infrastructure (what you have), and calculates exactly what actions it needs to take to make reality match your code.

The Comparison Process

When you run terraform plan, Terraform performs three key steps:

  1. Reads your configuration – Parses all .tf files to understand your desired state
  2. Refreshes current state – Queries your cloud provider APIs to see what actually exists right now
  3. Calculates the diff – Compares the two and determines what needs to be created, updated, or destroyed

Understanding the Output

The plan shows you:

  • Resources to add (marked with +)
  • Resources to change (marked with ~)
  • Resources to destroy (marked with -)
  • Resources that will be replaced (marked with -/+)

This preview is completely read-only—no infrastructure changes happen during terraform plan. It's your safety net to catch mistakes before they become expensive cloud resources.

Why This Matters

Without terraform plan, you'd be making blind changes to production infrastructure. The plan command gives you confidence by showing exactly what Terraform intends to do, letting you catch errors, unintended deletions, or unexpected resource replacements before they happen.

Key Takeaway: terraform plan generates a safe, previewable execution plan by comparing your desired configuration against current infrastructure state, showing you exactly what will change before you apply anything.