Agent Wranglers

INF-38Recommended

Scan infrastructure code on every change

Run an infrastructure scanner on every pull request, and fail the build on any finding rated high or critical.

How to do it

Use a scanner such as Checkov or Trivy's config scan, which replaced tfsec. Both read Terraform, OpenTofu, CloudFormation, Kubernetes files and Dockerfiles. They know hundreds of common mistakes, such as public buckets and open ports. Pin the scanner's version, as you pin any tool in CI. Checkov fails on every failed check, not only high ones, so list accepted skips as in let every exception expire. Run it in the same pipeline as every other check.

Examples

Shell example

trivy config --severity HIGH,CRITICAL --exit-code 1 infra/
checkov --directory infra/ --framework terraform --compact --quiet   # exit 1 on any failed check

How to check

Add a bucket with public read access in a test branch. The CI scan fails and names the resource.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/policy-as-code/scan-infrastructure-code">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.