Skip to main content
11.06.2026

Terraform Auto-Apply Policy Gates

head-image

Manual Terraform review is useful, but it does not scale cleanly. As change volume grows, reviewers become a queue and safe plans wait behind risky ones. A recent DevOps discussion around safe Terraform auto-apply with Conftest is a good reminder that the better boundary is not "human or automation." It is explicit policy.

Terraform can export a plan as JSON with terraform show -json. Conftest can evaluate that JSON with Open Policy Agent policies written in Rego. That gives platform teams a repeatable gate for deciding which plans can apply automatically and which plans need a person.

What Is The Pattern?

Generate a Terraform plan, convert it to structured JSON, run policy tests, and only auto-apply when the plan passes every rule.

terraform plan -out=plan.tfplan
terraform show -json plan.tfplan > plan.json
conftest test plan.json

If Conftest returns success, the pipeline can apply the saved plan file. If it returns a denial, the pipeline stops for review. The same input produces the same decision every time, which is easier to audit than a plan that "looked fine."

Why SRE Teams Should Care

Auto-apply is not mainly a speed feature. It is a risk segmentation feature. Low-risk infrastructure changes should not wait behind database replacements, IAM changes, or production network edits.

A policy gate lets teams encode their operational standards:

  • Allow creates for approved resource types.
  • Block deletes and replacements by default.
  • Limit the number of changed resources.
  • Require review for production tags, IAM, DNS, databases, and networking.
  • Allow harmless tag updates or monitoring threshold changes.

That makes the review process more focused. Humans spend attention where judgment matters.

Example Policy

A starting policy can deny updates, deletes, and replacements while allowing no-op, read, and create actions:

package main

import rego.v1

safe_actions := {"no-op", "read", "create"}

deny contains msg if {
  some change in input.resource_changes
  some action in change.change.actions
  not action in safe_actions
  msg := sprintf("%s uses unsafe action %s", [change.address, action])
}

This is deliberately conservative. Extend it with resource type allowlists, environment rules, and blast radius limits before enabling auto-apply in shared environments.

CI Rollout

Start with reporting mode. Run Conftest in CI, publish denials as build output, but keep the existing human approval path. After a week, inspect which plans would have passed.

Then create a separate auto-apply lane for a narrow class of changes. Good candidates include staging-only resources, monitoring rules, dashboards, or tag-only updates.

Pin the Terraform plan that was tested. The pipeline should apply the same plan.tfplan file that Conftest evaluated, not create a fresh plan after the policy check.

Operational Tips

Keep policies versioned beside infrastructure code. Add unit tests for policy rules. Log the Conftest output as an artifact, because it becomes part of the change record.

AI can explain a plan or suggest policy updates, but production apply decisions need deterministic rules that auditors and on-call engineers can reproduce.

Conclusion

Terraform auto-apply works best when it is boring. A Conftest policy gate gives teams a clear contract: small, approved changes move fast, while higher-risk plans still get human attention. That improves throughput without turning infrastructure changes into guesswork.

Need better control over production automation? Akmatori helps SRE teams detect, explain, and resolve operational issues with AI agents built for real infrastructure workflows. Akmatori runs on Gcore infrastructure for reliable global performance.

Automate incident response and prevent on-call burnout with AI-driven agents!