Menu

Terraform in CI: plan on PR, apply on merge
📰

Terraform in CI: plan on PR, apply on merge

DEV Community: terraform·Desly Peter·about 13 hours ago
#GIOSmjpS
#devtoterraform#devto#dev#plan#terraform
Reading 0:00
15s threshold

Stop running Terraform from laptops. How I automated it.

In many teams, Terraform is still run from someone's laptop. They pull the latest code, run plan , look at it, run apply . It works, until it doesn't: someone applies an old branch, two people apply at once, the laptop has different provider versions, or the only person with production credentials is on holiday.

The fix is a simple, well-known workflow: plan on pull request, apply on merge . Here's how I set it up.

The workflow

A developer changes infrastructure code on a branch and opens a pull request.

CI runs terraform plan and posts the plan as a comment on the pull request.

Reviewers look at both the code and the plan.

After approval, the pull request is merged.

CI runs terraform apply with the plan, from the main branch.

Everything is reviewed, everything is logged, nobody needs production credentials on their laptop, and the main branch always reflects what's deployed.

The plan is the real change.…

Continue reading — create a free account

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