Terraform Plan [Tricks] – What you should know about
When you start learning Terraform, the first thing you’ll run is terraform plan. It sounds simple, but understanding what it does will save you from costly mistakes later.
Terraform’s main job is to create, modify, and delete infrastructure based on code you write. People usually mean “plan, apply, destroy” when they talk about “running Terraform.”
What is Terraform Plan?
After running terraform init to download dependencies into the .terraform folder, you run terraform plan to see what changes Terraform will make.
What does Terraform Plan do?
Say you deploy a server to AWS. Later, you want to check if that server still exists. How does Terraform know?
It knows because Terraform tracks all resources in the Terraform State file. When you run terraform plan, it compares your current code against the state file and shows you the difference. It’s similar to how Git works: you fetch from remote, compare your changes, then push.
After comparing the current state with your desired state, terraform plan shows a report of what needs to change. But here’s the key point: nothing actually changes until you run terraform apply.
The plan command also validates your configuration syntax, so you catch errors early.
Parameters
You can combine several options with terraform plan to change its behavior:
-
target=ADDRESS — Focus on a specific resource. See the Terraform Target guide for details.
-
replace=ADDRESS — Force replacement of a specific resource.
-
refresh=BOOLEAN — Be careful with this one. If you set it to
false, Terraform won’t update the state file with the latest resource status.
Using Plan with Variables
You can pass variables directly to the plan command:
terraform plan -var 'KEY=VALUE'
You can add multiple variables by repeating the -var flag:
terraform plan -var 'instance_type=t3.micro' -var 'environment=dev'
Or use a variable file instead:
terraform plan -var-file="terraform-variables.tfvars"
Repeat -var-file for each additional file you need.
Plan to File
You can save a plan to a file, then apply it later:
terraform plan -out=tfplan
The -out flag saves the plan to a binary file. You then pass this file to terraform apply tfplan to execute exactly those changes.
Output Example

Always read the plan output carefully before running apply. The output shows which resources will be created, modified, or destroyed. If you’re working with a team on a shared branch, pay extra attention to the plan. Accidentally destroying resources is easier than you think when your local state differs from the remote.
For running scripts or commands that don’t map to a real cloud resource, see Terraform Null Resource — it’s the right tool for local-exec provisioners, file uploads, and post-deployment steps inside your Terraform workflow.
Taking plan validation further? Terraform testing in 2026 covers native terraform test, Terratest, and OPA policy validation.
Comments