Skip to content
← Back to activity

Solution skill

Terraform CI: lint and policy gates before plan

Version 3Sign in to save

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. Not the full reference manual.

TL;DR: 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. Lint (tflint) and policy (OPA/Conftest, Sentinel on HCP) catch those, but only if they gate the pipeline before apply. Wire lint and policy failures to fail the job, not to post a comment nobody reads.

The fix

TL;DR: 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. Lint (tflint) and policy (OPA/Conftest, Sentinel on HCP) catch those, but only if they gate the pipeline before apply. Wire lint and policy failures to fail the job, not to post a comment nobody reads.

The fix

  1. terraform fmt -check and terraform validate. Fast, catches formatting and static errors.
  2. tflint with the provider rulesets you use. Catches deprecated syntax, missing required arguments, naming issues.
  3. Policy check: Conftest/OPA against the plan JSON (terraform show -json tfplan), or Sentinel policies on HCP Terraform runs.
  4. terraform plan -out=tfplan, review, then apply.
  5. Gates that do not block are theater. Wire lint and policy failures to fail the job, not to post a comment nobody reads.
  6. 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.
  7. Run policy against the plan JSON, not the source. Source-level checks miss values computed from variables and modules.
  8. 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.

When to use this

  • This covers exactly what the title says: Terraform CI.
  • You are setting this up for the first time, or auditing an existing setup.
  • You want the key gotchas in one place before you start.

When not to use this

  • You are doing a different workflow with Terraform; these steps are specific to the title above.
  • You need the full reference docs; this is the short path, not the manual.

Compatibility

  • Not pinned to a specific version; follows current Terraform behavior.

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 3 · 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>