Supply chainTerraform · Trivy
Scan Terraform before it applies: Checkov and Trivy
Checkov and Trivy both scan Terraform for misconfigurations, on the HCL code or on a plan. Their documentation states what each mode can see, how to skip a check with a reason and how to control the exit code.

Checkov on code and on a plan
Checkov evaluates its policies on resources declared in .tf files. It can also evaluate a Terraform plan expressed as a JSON file.
# the code
checkov -d .
# the plan
terraform init
terraform plan --out tfplan.binary
terraform show -json tfplan.binary > tfplan.json
checkov -f tfplan.json --repo-root-for-plan-enrichment .With --repo-root-for-plan-enrichment, the code blocks and resource IDs in the output come from the Terraform files, and their skip comments are respected. Adding --deep-analysis combines the graph of the plan scan with the graph of the Terraform files. Checkov can then make connections where the plan holds incomplete information, such as locals.
A third-party module abstracts its resources away from a scan of the current directory. checkov -d . --download-external-modules true makes Checkov download the modules into a folder named .external_modules and cover them.
Trivy configuration scanning
trivy config --severity HIGH,CRITICAL --exit-code 1 .
trivy config --tf-vars prod.tfvars ./infrastructure
terraform plan --out tfplan
trivy config tfplantrivy config recursively searches a directory and scans all the Terraform files it finds. It supports HCL, JSON, a plan snapshot and a plan in JSON. --tf-vars passes a tfvars file that overrides the default values in the HCL code. The file and directory names here are yours to replace.
Trivy downloads modules whose source is remote. Downloading is on by default, and no CLI option turns it off. Its documentation warns about the consequence: a scan of an untrusted configuration can send network requests to hosts the configuration's author picked. With --tf-exclude-downloaded-modules, the modules are still downloaded and evaluated, but their findings are marked as ignored.
Where tfsec stands
tfsec, in the aquasecurity/tfsec repository, uses static analysis of Terraform code to spot potential misconfigurations. Its README opens with a migration notice: Aqua is consolidating its scanning work in Trivy and encourages the tfsec community to transition over. tfsec will remain available for the time being, with engineering attention directed at Trivy. The latest release on the repository's releases page is v1.28.14, published on 2 May 2025.
For a new pipeline, use trivy config. The tfsec repository holds a migration guide.
Skip comments that carry a reason
Both tools let you suppress a check on one resource. These are the examples from their documentation:
resource "aws_s3_bucket" "foo-bucket" {
region = var.region
#checkov:skip=CKV_AWS_20:The bucket is a public static content host
bucket = local.bucket_name
force_destroy = true
acl = "public-read"
}
#trivy:ignore:aws-s3-enable-logging:exp:2024-03-10
resource "aws_s3_bucket" "example" {
bucket = "test"
}- Checkov: the pattern is
checkov:skip=<check_id>:<suppression_comment>, placed inside the scope of the resource. The suppression comment is optional. Checkov includes it in the output, on a line that starts with "Suppress comment". - Trivy: the format is
trivy:ignore:<rule>, immediately adjacent to the resource definition. The rule is a check ID, its long ID in the form provider-service-short-code, or an alias.:exp:with a date inyyyy-mm-ddformat ends the ignore on that date.
Trivy's inline ignores work only for checks associated with an existing resource. A check triggered by the absence of a resource cannot be ignored inline, and the documentation points to a .trivyignore.yaml file for it. An entry in that file has a statement field for the justification.
A soft fail before a hard gate
The two tools have opposite defaults. Checkov's exit code is 1 unless all checks pass or are skipped. Trivy exits with code 0 even when it detects issues, unless you set --exit-code.
Roll the gate out in three steps:
- Report only. Run
checkov -d . --soft-fail, which always returns a 0 exit code, or Trivy with no--exit-code. - Fail on a short list. With
--hard-fail-onand a list of check IDs, a failed check that is not on the list results in a soft fail. In Trivy, set--severity CRITICAL --exit-code 1. - Widen the list as findings get fixed or skipped.
--hard-fail-on and --soft-fail-on accept check IDs and severities. For --check and --skip-check, Checkov's documentation states that filtering by severity requires the platform integration with an API key. The steps above use check IDs.
Plan or code
The code. Trivy describes its scan of Terraform code as static analysis that does not execute provider calls. Values from data sources and computed attributes are treated as unknown, which can lead to false positives or false negatives.
The plan. Checkov's documentation says plan evaluation gives it additional dependencies and context, which can result in a more complete scan. It lists these points:
- Plan files may contain arguments such as secrets, so it advises running the plan scan in a secure CI/CD pipeline.
- Four checks are ignored on plan files. They evaluate the
lifecycleblock, which is not stored in the plan. - Enrichment with
--repo-root-for-plan-enrichmentadds the skip comments from the Terraform files to the plan scan.
Trivy adds a limit for the JSON plan: it does not carry complete reference information for expressions that use each or count, so some references between resources cannot be established.
Run both: the code scan on pull requests, and the plan scan in the stage that creates the plan.
Where to start
- Add the code scan with
--soft-fail, or with no--exit-codein Trivy. - Go through the first report. Fix what is wrong, and skip what is intended with a comment.
- Agree on the first check IDs for
--hard-fail-on. - Add the plan scan to the pipeline that runs
terraform plan.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

Policy as code: test Terraform plans with OPA and Conftest
Infrastructure as code · 3 min read
Convert the plan to JSON, write one Rego rule, and fail the pipeline when it matches.

Where to keep Terraform state, and how to lock it
Infrastructure as code · 2 min read
Remote backends on AWS, Azure and Google Cloud, one state per environment.

Signed commits: GPG, SSH and what the Verified badge proves
Supply chain · 4 min read
SSH signing in four commands, what Verified means, and why rebase merges lose verification.