/flags/terraform/terraform-plan-out
terraform plan -out: save a plan and apply exactly that plan
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash) · Terraform v1.16.6updated 2026-10-20
- tool
- Terraform
- command
- terraform plan
- flag
- -out=FILE
- default
- plan is printed only
terraform plan -out=tfplan saves the proposed changes to a binary plan file. terraform apply tfplan applies exactly that plan, without a confirmation prompt and without re-reading changes made to the configuration afterwards. This is how CI pipelines split "plan, review, approve" from "apply".
Save and inspect a plan
printf 'resource "terraform_data" "app" {\n input = "v1"\n}\n' > main.tf
terraform init -input=false -no-color >/dev/null
terraform plan -no-color -input=false -out=tfplan | tail -4
terraform show -no-color tfplan | sed -n '/will be created/,/^$/p'
terraform show -json tfplan | head -c 60; echoOutput
Saved the plan to: tfplan
To perform exactly these actions, run the following command to apply:
terraform apply "tfplan"
# terraform_data.app will be created
+ resource "terraform_data" "app" {
+ id = (known after apply)
+ input = "v1"
+ output = (known after apply)
}
{"format_version":"1.2","terraform_version":"1.16.6","planneterraform show -json tfplan produces the machine-readable plan used by policy tools (OPA/Conftest, Sentinel) and PR comments.
Things to know
- The plan file is tied to the state it was made from. If the state changes before apply (someone else applied), apply refuses with
Saved plan is stale; plan again. - The file contains every variable value and attribute in clear text, including sensitive ones. Treat it like a secret: short-lived CI artifacts, never committed.
- Use the same Terraform version, providers (
.terraform.lock.hcl) and working directory for plan and apply. - Without
-out,terraform applycreates a new plan and asks for confirmation;-auto-approveskips the question but not the new plan.
Sources
Related pages
codes · terraformterraform plan -detailed-exitcode: exit codes 0, 1 and 2With -detailed-exitcode, terraform plan exits 0 when there are no changes, 1 on error and 2 when the plan has changes. Use it in CI for drift detection.cheat sheets · terraformTerraform cheat sheet: init, plan, apply, state and workspacesTerraform cheat sheet: init and upgrade, fmt and validate, plan and apply, outputs, state list, mv and rm, import, workspaces, and common language syntax.glossary · terraformWhat is Terraform state?Terraform state is the JSON record that maps each resource address in your code to the real object it manages and its last known attributes: terraform.tfstate.