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
.tfscan 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."
More on Checkov
What is Checkov and how do you scan Terraform with it?BeginnerWhat is IaC security scanning and why is it needed?BeginnerWhat is Checkov?BeginnerHow do you scan Terraform code with Checkov?BeginnerHow do you scan Kubernetes manifests and Dockerfiles with Checkov?BeginnerHow do you skip a Checkov check with a documented reason?Intermediate