Execution Plans and the Resource Graph
terraform plan shows what Terraform will do before it does anything. This lesson explains how to read a plan, how Terraform orders work through the resource graph, and the options that shape a plan.
Learning outcomes
After completing this lesson, you will be able to:
- Interpret the actions and symbols in an execution plan.
- Explain how the resource graph orders and parallelises operations.
- Describe saved plans and the main planning options.
How a plan is made
When you run terraform plan, Terraform reads the configuration and the latest state, refreshes the state by reading every managed object, and compares the result with the configuration. Every difference becomes a proposed action. Plan never changes real infrastructure or the stored state, so it is always safe to run.
Terraform will perform the following actions:
# aws_instance.web must be replaced
-/+ resource "aws_instance" "web" {
~ ami = "ami-0aaa1111" -> "ami-0bbb2222" # forces replacement
~ id = "i-0abc123" -> (known after apply)
instance_type = "t3.micro"
}
# aws_s3_bucket.logs will be created
+ resource "aws_s3_bucket" "logs" {
+ arn = (known after apply)
+ bucket = "acme-logs-witty-fox"
}
Plan: 2 to add, 0 to change, 1 to destroy.The symbols identify the action for each resource, as listed in the following table.
| Symbol | Action |
|---|---|
| + | Create a new object |
| ~ | Update the object in place |
| - | Destroy the object |
| -/+ | Destroy, then create a replacement (default replacement order) |
| +/- | Create the replacement first, then destroy (create_before_destroy) |
| <= | Read a data source during apply |
A replacement counts as one add and one destroy in the summary, which is why the example shows two adds. The comment # forces replacement identifies the argument whose change cannot be made in place. Values that the provider computes, such as IDs and ARNs, appear as (known after apply).
The following diagram shows a plan that forces replacement because of drift, and the safe responses.

Reading plan symbols
The resource graph
Terraform builds a dependency graph from the configuration. Each resource, data source, provider configuration, variable and output is a node, and each reference or depends_on entry is an edge. Terraform walks the graph so that an object is created or updated after everything it depends on, and destroyed before everything it depends on.
Nodes with no path between them are independent and are processed in parallel. By default Terraform performs up to 10 operations concurrently; -parallelism=N on plan, apply or destroy changes the limit, which helps when a provider hits API rate limits. terraform graph prints the graph in DOT format, which tools such as Graphviz can draw. If references form a cycle, Terraform reports an error during planning.
10
Default number of concurrent operations
0 / 1 / 2
-detailed-exitcode results: no changes / error / changes
Plan summaries and parallelism
Saved plans and planning options
terraform plan -out=tfplan saves the plan to a binary file. terraform apply tfplan later performs exactly those actions without asking again, which separates review from execution in pipelines. terraform show tfplan prints a saved plan, and terraform show -json tfplan produces JSON for policy tools. A plan file contains the configuration and values, which can include secrets, so protect it like state.
Plan has three modes: normal, -destroy, which plans to destroy everything, and -refresh-only, which only updates state to match reality. The following options are used most often.
| Option | Effect |
|---|---|
| -var 'name=value' and -var-file=FILE | Set input variables |
| -target=ADDRESS | Plan only the given resource and its dependencies; for exceptional situations |
| -replace=ADDRESS | Plan to replace the given resource even if it has not changed |
| -refresh=false | Plan from cached state without reading real infrastructure |
| -detailed-exitcode | Exit 0 for no changes, 1 for an error, 2 for changes |
| -out=FILE | Save the plan for a later apply |
Avoid routine targeting
-target is not a routine way to work on part of a configuration: it can leave the rest out of step, and Terraform warns every time it is used. Split large configurations into separate root modules or workspaces instead.
Planning options
An unexpected replacement
A plan for a small tag change shows -/+ for a production database with # forces replacement next to engine_version. The engineer did not change the engine version. What should they do?
The decisive information is the forcing argument and the refresh step.
Refresh shows the real engine version, which may have been upgraded outside Terraform, for example by automatic minor version upgrades, so the configuration's older value now differs. The engineer must not apply: replacing a database destroys its data. They should update the configuration to the current version, or add the attribute to ignore_changes if the platform manages it, and plan again until only the tag change appears.
What exit code does terraform plan -detailed-exitcode return when changes are present?
Show answer
2. It returns 0 when there are no changes and 1 on an error.
Exam Tips
Remember for the exam
- plan refreshes, compares and proposes; it changes nothing.
- -/+ is a replacement; look for # forces replacement.
- Default parallelism is 10; the graph orders work by dependencies.
- plan -out saves a plan; protect plan files like state.