Write a conftest policy in Rego to enforce Terraform IaC rules and run it in CI

domain: conftest.dev · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Install conftest from the official releases and verify with `conftest --version`; it parses Terraform HCL, JSON plan output, Kubernetes YAML, and over 18 other formats.
  2. Run `terraform show -json tfplan > plan.json` to export the plan as structured JSON that conftest can parse.
  3. Write a Rego policy file, e.g. `policy/main.rego`, with `package main` and denial rules such as `deny[msg] { ... }`.
  4. Execute `conftest test plan.json --policy policy/` from the repo root; conftest evaluates each deny and warn rule and exits non-zero if any denial fires.
  5. Add `conftest pull` with an OCI registry path to distribute shared policy bundles across teams without copying Rego files into every repo.
  6. Integrate the conftest step into your CI pipeline between `terraform plan` (with `-out`) and `terraform apply`.

Known gotchas

Related routes

Enforce Terraform plan policies in Spacelift using a plan policy written in Rego
docs.spacelift.io · 6 steps · unrated
Use conftest to policy-test Kubernetes manifests and Terraform plan JSON against Rego policies in a CI pipeline
security/compliance · 5 steps · unrated
Write an OPA Rego policy to enforce that all Kubernetes Deployments have resource requests and limits set, and integrate it with Conftest in a CI pipeline
www.openpolicyagent.org · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans