Menu

Apply the plan you reviewed: saved Terraform plans in CI
📰

Apply the plan you reviewed: saved Terraform plans in CI

DEV Community: terraform·Hritik Chaudhary·9 days ago
#F5ZSWZ9r
#devtoterraform#devto#dev#plan#apply
Long article (402 words) — no AI summary yet.
Reading 0:00
15s threshold

Most Terraform pipelines run terraform plan on the pull request, a human reads it, and then a different job runs terraform apply -auto-approve after the merge. Those are two separate plans. Anything that changed in between, such as another merge, a manual console edit or a provider update, gets applied without anyone having read it.

The fix is small: apply the plan file the reviewer actually saw.

The two commands

terraform plan -input=false -lock-timeout=60s -out=tfplan terraform apply -input=false tfplan

Enter fullscreen mode

Exit fullscreen mode

terraform apply tfplan does not plan again. It applies exactly what is in the file. If the state has changed since the plan was made, Terraform refuses with a "saved plan is stale" error instead of applying something nobody reviewed. That refusal is the feature.

Showing the plan to a human

A plan file is binary.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.