terraform plan
Terraform plan is a preview of the changes a configuration would make. It shows what will be added, changed or destroyed, and changes nothing.
Reading a plan: add
The plus sign marks a new resource. The block shows the values it will have.
Terraform will perform the following actions:
# local_file.hello will be created
+ resource "local_file" "hello" {Reading a plan: change
The tilde marks a change. The arrow shows the old value and the new value.
~ resource "local_file" "hello" {
~ content = "Old text." -> "New text."
}The summary line
The last line counts the changes. It is the quickest check of the whole plan.
Plan: 1 to add, 0 to change, 0 to destroy.Example
# main.tf
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "2.9.1"
}
}
}
resource "local_file" "hello" {
filename = "hello.txt"
content = "Hello from Terraform."
}
# Commands:
# terraform init
# terraform plan
# terraform apply
# terraform destroyKey points
- Plan compares the configuration with the current state.
- A plus sign means a resource will be added.
- A tilde means a resource will be changed in place.
- A minus sign means a resource will be destroyed.
- Plan changes nothing. It only reports what apply would do.
- Read the plan every time, even for a small change.
Plan reads the file and the current state. It lists one resource to add and nothing to change or destroy. Apply would then carry out exactly that list, and destroy removes the file after practice.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
Why run terraform plan before terraform apply?