Skip to main content

What Happens During a Terraform Plan

Introduction #

One of Terraform’s most useful features is the plan step.

Instead of making changes immediately, Terraform can first show what it believes needs to happen. That gives engineers a chance to validate the change before resources are created, modified, or destroyed.

Understanding what happens during terraform plan makes the output much less mysterious.

The Goal of a Plan #

The goal of a plan is to compare:

  • What the configuration says should exist
  • What the state file says is already managed
  • What the real infrastructure currently looks like

Terraform uses those inputs to determine the actions needed to move from the current state to the desired state.

Step 1: Read the Configuration #

Terraform first loads the configuration in the working directory.

That includes:

  • Resource definitions
  • Variable values
  • Provider settings
  • Module references

At this point, Terraform is understanding the desired design expressed in code.

Step 2: Load State #

Terraform then reads the current state data.

The state file helps Terraform understand which real resources it already manages and how those resources map to the configuration.

Without state, Terraform would not have a dependable memory of earlier actions.

Step 3: Refresh Resource Information #

Terraform checks the provider to learn the current real-world status of managed resources.

This matters because infrastructure can drift. Someone may have changed a setting in the portal, deleted a resource manually, or altered something through another tool.

The refresh behavior helps Terraform compare reality, not just old assumptions.

Step 4: Build the Execution Graph #

Terraform works out dependencies between resources.

For example, a subnet may depend on a virtual network, and a virtual machine may depend on the subnet.

This dependency graph helps Terraform decide the correct order for any later actions.

Step 5: Calculate the Diff #

Once Terraform understands the desired configuration and the current infrastructure, it calculates the difference.

That diff may show:

  • Resources to add
  • Resources to change
  • Resources to destroy

This is the part most users focus on, because it is the clearest preview of impact.

Why the Plan Step Is So Valuable #

The plan step reduces surprises.

It helps teams:

  • Catch incorrect values before apply
  • Notice accidental deletions
  • Review infrastructure drift
  • Understand blast radius

In a collaborative workflow, this preview is often one of the most important approval points in the process.

Conclusion #

terraform plan is more than a dry run. It is Terraform’s reasoning step.

It reads the code, checks the current state, compares against real infrastructure, and tells you what actions would be needed next. That visibility is a major reason Terraform is so useful in controlled infrastructure workflows.