Why scan the Terraform plan with Checkov instead of only the .tf files?

IntermediateConceptCheckov
Answer

Short answer

Scanning .tf files sees the code as written — variables, modules and computed values may be unknown. Scanning the plan JSON sees the final resolved values that Terraform will actually create, including resources from external modules. Plan scanning is more accurate and catches issues hidden behind variables.

Example of the difference

resource "aws_db_instance" "main" {
  publicly_accessible = var.public_db     # .tf scan can't know the value
}

With public_db = true in prod.tfvars, only the plan reveals the database will be public.

How to scan a plan

terraform init
terraform plan -var-file=prod.tfvars -out=tfplan
terraform show -json tfplan > tfplan.json
checkov -f tfplan.json --framework terraform_plan

Best of both

  • .tf scan on every PR — fast, no cloud credentials needed.
  • Plan scan in the pipeline before apply — accurate, per environment.

What to say in the interview

"File scanning can't resolve variables or remote modules, so we also scan terraform show -json of the plan with the terraform_plan framework. It reflects exactly what will be created per environment and catches things like a database made public through tfvars."

All Security Tools questions Roadmap: Checkov — IaC security

More on Checkov