Twenty teams run Terraform from CI. Applies collide, plans go stale, and reviews are rubber stamps. How do you fix it?
AdvancedScenarioPipelines at scale
Answer
Situation read → Plans are only valid against the state they were made from. Without locking, ordering and a clear plan in the PR, applies become risky.
What I'd do →
- Split state into small stacks per team and component, so teams rarely share a lock.
- Use state locking (S3
use_lockfileor a TACOS tool) and queue applies per stack. - Plan on PR, post the plan as a comment, and apply the saved plan after merge; if the state moved since, re-plan and require re-approval.
terraform plan -out=tfplan -input=false
terraform apply -input=false tfplan
- Make reviews meaningful: policy checks (OPA/Conftest, Checkov) flag destroys, public resources and IAM wildcards, so humans focus on what matters.
- Consider Atlantis, Spacelift, env0 or HCP Terraform; they handle locking, plan-per-PR and policy for you.
Why → A saved plan applied as reviewed is the only way to guarantee "what was approved is what changed".
Interview tip → Say "apply the saved plan file"; applying a fresh plan after approval defeats the review.
More on Pipelines at scale
The CI pipeline takes 45 minutes. Developers want it under 10. How do you approach it?IntermediateYou have a monorepo with 40 services. Every commit builds and tests all of them. How do you fix that?AdvancedFlaky tests fail 1 in 5 runs and developers just click "re-run". How do you fix this culture and the tests?BeginnerYour self-hosted GitHub runners can't keep up at peak and sit idle at night. How do you run them at scale?AdvancedDocker builds in CI take 12 minutes because every runner starts with an empty cache. How do you speed them up?IntermediateHow do you secure the software supply chain from commit to production?Advanced