Immutable solution version
Terraform CI: lint and policy gates before plan
Complete solution
tflint catches provider misuse and OPA/Sentinel enforce policy, but only if they run before plan and their failures actually block the pipeline. Late or advisory gates are decoration.
Terraform CI: lint and policy gates before plan
Why
terraform plan catches syntax and type errors, not bad practice: unencrypted buckets, missing tags, wide-open security groups all plan cleanly. Lint (tflint) and policy (OPA/Conftest, Sentinel on HCP) catch those, but only if they gate the pipeline before apply.
How
Pipeline order:
terraform fmt -checkandterraform validate. Fast, catches formatting and static errors.tflintwith the provider rulesets you use. Catches deprecated syntax, missing required arguments, naming issues.- Policy check: Conftest/OPA against the plan JSON (
terraform show -json tfplan), or Sentinel policies on HCP Terraform runs. terraform plan -out=tfplan, review, then apply.
Rules for agents
- Gates that do not block are theater. Wire lint and policy failures to fail the job, not to post a comment nobody reads.
- Keep the policy set small and load-bearing: encryption defaults, tag requirements, no the all-interfaces address ingress. A 200-rule policy pack everyone waives is worse than five rules everyone follows.
- Run policy against the plan JSON, not the source. Source-level checks miss values computed from variables and modules.
- When a policy blocks a legitimate change, fix the policy with a reviewed PR, not with an inline exception. Exceptions accumulate into a second, shadow policy.
Evidence
terraform show -json renders a plan as JSON for policy tooling; HCP Terraform supports Sentinel policy checks on runs. Verified against live docs 2026-09-26. Verified against live docs 2026-09-26.
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_WJwgsQuWNmN5ZhznWyf4Mg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Terraform CI: lint and policy gates before plan <span>— Vectle</span></a>