What is Checkov and how do you scan Terraform with it?
Short answer
Checkov is a free tool from Prisma Cloud that scans infrastructure as code — Terraform, CloudFormation, Kubernetes YAML, Helm charts and Dockerfiles — for security misconfigurations, such as public S3 buckets, unencrypted databases or security groups open to the whole internet. Run checkov -d . and it reports every failed check.
Why it matters
Many cloud breaches aren't clever hacks — they're simple mistakes, like a storage bucket made public. Checkov catches these mistakes in the code, before terraform apply creates the insecure resource.
Example — a Terraform file with problems
resource "aws_s3_bucket" "reports" {
bucket = "company-reports"
}
resource "aws_security_group" "web" {
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # SSH open to the entire internet!
}
}
pip install checkov
checkov -d ./terraform
Output (shortened):
Check: CKV_AWS_24: "Ensure no security groups allow ingress from 0.0.0.0:0 to port 22"
FAILED for resource: aws_security_group.web
File: /main.tf:5-13
Check: CKV2_AWS_6: "Ensure that S3 bucket has a Public Access block"
FAILED for resource: aws_s3_bucket.reports
Passed checks: 12, Failed checks: 2, Skipped checks: 0
Other useful commands
checkov -f k8s/deployment.yaml # scan one Kubernetes file
checkov -d . --framework dockerfile # only Dockerfiles
checkov -d . --soft-fail # report, but don't fail the build
checkov -d . --output junitxml > checkov.xml # report for CI dashboards
Skip a check on purpose, with a reason:
resource "aws_s3_bucket" "website" {
# checkov:skip=CKV2_AWS_6:Public static website bucket, approved by security (ticket SEC-142)
bucket = "company-public-site"
}
Where it fits in the pipeline
terraform fmt → terraform validate → checkov → terraform plan → approval → terraform apply
What to say in the interview
"Checkov is a static scanner for infrastructure as code. We run checkov -d . in the Terraform pipeline after validate and before plan, so misconfigurations like open security groups, public buckets or unencrypted storage fail the build before anything is created. Exceptions are skipped in the code with a reason and a ticket number, so there's an audit trail. It also scans Kubernetes manifests and Dockerfiles."
Follow-up questions you may get
- Alternatives? tfsec (now part of Trivy, via
trivy config), Terrascan, KICS. - Can you write your own rules? Yes — custom policies in Python or YAML.