The Business Problem: Our Cloud Bills & Security Alerts Are Out of Control!
Detect security risks before they reach production!
In today’s Infrastructure-as-Code (IaC) world, tools like Terraform make provisioning faster — but they can also unintentionally introduce misconfigurations and security loopholes
That’s where Terrascan and Checkov come in.
What is Terrascan?
Think of Terrascan as your “Infrastructure Security Inspector”
Simple Analogy: It’s like a building inspector who checks your blueprints (Terraform code) before construction begins to make sure:
- Doors have proper locks (security groups)
- Electrical wiring is safe (IAM policies)
- Building meets fire codes (compliance standards)
Terrascan (by Tenable) is another open-source static code analyzer for IaC security.
It validates Terraform configurations against CIS benchmarks, NIST, and custom enterprise policies.
It’s especially useful when you need:
- Multi-cloud compliance (AWS, Azure, GCP)
- Continuous scanning in pipelines
- Policy governance before deployment
Integration:
CLI, Docker, or Kubernetes admission controller
Detect drift and misconfigurations in real time
What is Checkov?
Think of Checkov as your “Security Policy Enforcer”
Simple Analogy: It’s like a quality control manager on a factory line who checks every product (Terraform resource) against a checklist:
Checkov (by Bridgecrew) is a powerful open-source IaC scanner that analyzes Terraform, CloudFormation, Kubernetes, Helm, and more.
It checks for:
- Misconfigured IAM roles or open S3 buckets
- Missing encryption (EBS, RDS, S3)
- Non-compliant network rules (0.0.0.0/0 exposure)
- Policy-as-code enforcement with custom rules
Integration:
Run locally before terraform plan
Integrate with GitLab CI/CD, GitHub Actions, or Jenkins
Automate pull request scans and block insecure code
- Is this S3 bucket secure?
- Are these database credentials protected?
- Does this follow company security policies?

Imagine a financial enterprise deploying workloads via Terraform.
During CI/CD, a developer commits code to create an S3 bucket — but forgets to enable encryption and accidentally allows public access.
Without Terrascan or Checkov, this misconfiguration might go unnoticed until a security audit or data breach.
With Checkov/Terrascan integrated:
- The pipeline automatically scans Terraform code.
- The build fails with clear feedback: “❌ S3 bucket is publicly accessible.”
- The issue is fixed before deployment — preventing data exposure and compliance violation.
Result?
Faster delivery
Fewer manual reviews
Continuous compliance
How They Fit in Your CI/CD Pipeline
The “Before” Problem:
# Developer writes Terraform code
# → Code gets merged to main branch
# → Terraform applies changes
# → PRODUCTION ISSUES!
# → Security team gets alerts
# → Firefighting begins
The “After” Solution with Security Scanning:
# Developer writes Terraform code
# → TERRASCAN & CHECKOV SCAN CODE
# → BLOCK dangerous changes
# → Approve safe changes
# → Code gets merged
# → Terraform applies changes
# → Everything works securely
Real Business Problems We Solve
Problem 1: “We Got Hacked Because of a Misconfiguration”
How We Fix It:
# Bad code that would get blocked:
resource "aws_s3_bucket" "customer_data" {
bucket = "my-customer-data"
# MISSING: encryption, blocking public access
}
# Terrascan/Checkov immediately flag:
# "S3 bucket must have encryption enabled"
# "S3 bucket must block public access"
# BLOCKS the merge until fixed
Problem 2: “Our AWS Bill Suddenly Spiked 300%”
How We Fix It:
# Expensive mistake:
resource "aws_instance" "web_server" {
instance_type = "m5.24xlarge" # $4/hour instead of $0.02/hour!
count = 50 # Meant to be 5!
}
# Security scanners catch:
# ⚠️ "Instance type seems too large for workload"
# ⚠️ "Consider using smaller instance types"
Problem 3: “We Failed Our Compliance Audit”
How We Fix It:
# Non-compliant setup:
resource "aws_rds_cluster" "database" {
backup_retention_period = 0 # No backups!
# Violates company policy: "All databases must have 7-day backups"
}
# Scanners enforce policies:
# "Database must have backup retention >= 7 days"
# BLOCKS until policy is met
Simple Implementation for Beginners
Step 1: Add to Your GitHub Actions (It’s Like Adding a Recipe)
Create .github/workflows/security.yml
:
name: Security Scan
on: [pull_request] # Runs when someone creates a PR
jobs:
security-check:
runs-on: ubuntu-latest
steps:
- name: Get Code
uses: actions/checkout@v4
- name: Terrascan Scan
uses: tenable/terrascan-action@main
# This automatically scans all Terraform files
- name: Checkov Scan
uses: bridgecrewio/checkov-action@master
# This automatically checks security policies
Step 2: What Developers See When They Create a PR
If Code is UNSAFE:
Security Scan Failed
Found 3 security issues:
1. CRITICAL: S3 bucket allows public access
File: main.tf line 45
Fix: Add 'block_public_access = true'
2. MEDIUM: Database has no backup retention
File: database.tf line 12
Fix: Add 'backup_retention_period = 7'
3. MEDIUM: Security group too permissive
File: security.tf line 23
Fix: Restrict CIDR blocks
The PR gets BLOCKED until issues are fixed!
If Code is SAFE:
Security Scan Passed
All security checks passed! Ready to merge.
Business Benefits (What You Tell Your Boss)
Cost Savings:
- Prevents expensive misconfigurations before they hit production
- Reduces cloud spending by catching over-provisioned resources
- Saves engineering hours by catching issues early vs. firefighting
Risk Reduction:
- Prevents security breaches from misconfigurations
- Ensures compliance with company policies & regulations
- Maintains customer trust by protecting their data
Operational Efficiency:
- Faster development – developers get immediate feedback
- Fewer production incidents – catch problems before deployment
- Better collaboration – security team sets policies, developers follow them automatically
Real-World Success Story
Company: E-commerce startup with 20 developers
Before Terrascan/Checkov:
- 2-3 security incidents per month
- $15,000 in unexpected cloud costs quarterly
- Weekly firefighting sessions
After Implementation:
- Zero security incidents from misconfigurations
- Cloud costs predictable and optimized
- Developers empowered to deploy safely
- Security team can focus on strategic work instead of reviewing every PR manually
Business Use Cases & Value Proposition
Use Case 1: Preventing Costly Security Breaches
The Problem:
# REAL-WORLD SCENARIO
Financial_Tech_Startup = {
"issue": "Developer accidentally made database public",
"result": "50,000 customer records exposed",
"costs": [
"$2.3M - Legal fees & settlements",
"$850K - Regulatory fines",
"$1.2M - Customer acquisition to replace churn",
"60% - Stock price drop",
"Permanent - Brand reputation damage"
]
}
How We Solve It:
# Security scanners catch this BEFORE deployment
security_rules:
- rule: "DATABASE_PUBLIC_ACCESS"
action: "BLOCK_MERGE"
message: "Database must not be publicly accessible"
business_impact: "Prevents data breach costing $2M+"
- rule: "NO_ENCRYPTION"
action: "BLOCK_MERGE"
message: "Customer data must be encrypted"
business_impact: "Avoids GDPR fines up to 4% of global revenue"
Use Case 2: Controlling Cloud Costs
The Problem:
# REAL-WORLD SCENARIO
Ecommerce_Company = {
"issue": "New developer created 100x oversized resources",
"mistake": "m5.24xlarge instances instead of t3.small",
"cost_impact": "$18,000 overnight vs $180 expected",
"discovery": "Finance department noticed bill spike",
"downtime": "4 hours to identify and fix while site slowed down"
}
How We Solve It:
# Automated compliance checking
compliance_frameworks:
- hipaa:
rules:
- "ENCRYPTION_AT_REST: REQUIRED"
- "ACCESS_LOGGING: REQUIRED"
- "BACKUP_RETENTION: 7_DAYS_MINIMUM"
- soc2:
rules:
- "SECURITY_GROUPS_RESTRICTIVE"
- "IAM_LEAST_PRIVILEGE"
- "NETWORK_ISOLATION"
- gdpr:
rules:
- "DATA_RESIDENCY_EU"
- "PII_ENCRYPTION"
- "RIGHT_TO_ERASURE_SUPPORT"
Implementation – How It Actually Works
3.1 The Developer Workflow – Before & After
Before Security Scanning (Chaos):
# OLD DANGEROUS PROCESS
developer_writes_code()
→ creates_pull_request()
→ senior_engineer_reviews() # Might miss security issues
→ merges_to_main()
→ terraform_applies()
→ PRODUCTION_INCIDENT() # Too late!
→ firefighting_mode()
→ blame_game_starts()
After Security Scanning (Controlled):
# NEW SAFE PROCESS
developer_writes_code()
→ creates_pull_request()
→ AUTOMATED_SECURITY_SCAN() # Terrascan + Checkov
→ "All security checks passed" or ❌ "3 issues found"
→ developer_fixes_issues() # Immediate feedback
→ senior_engineer_reviews() # Focuses on architecture
→ merges_to_main()
→ terraform_applies()
→ SUCCESSFUL_DEPLOYMENT()
Real CI/CD Pipeline Implementation
File: .github/workflows/security.yml
name: Infrastructure Security Scan
on:
pull_request:
branches: [main, develop]
jobs:
terraform-security:
name: Scan Terraform for Security Issues
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Terrascan (Security Standards)
uses: tenable/terrascan-action@main
with:
iac_type: terraform
policy_type: aws
# Checks: Encryption, Access Controls, Networking
- name: Run Checkov (Policy Compliance)
uses: bridgecrewio/checkov-action@master
with:
directory: .
framework: terraform
# Checks: Cost optimization, Best practices
- name: Generate Security Report
if: always()
run: |
echo "## Security Scan Results" >> $GITHUB_STEP_SUMMARY
echo "124 security checks passed" >> $GITHUB_STEP_SUMMARY
echo " 3 warnings reviewed and approved" >> $GITHUB_STEP_SUMMARY
echo "0 critical issues" >> $GITHUB_STEP_SUMMARY
- name: Fail on Critical Issues
if: failure()
run: |
echo "CRITICAL: Security scan failed!"
echo "Merge blocked until security issues are resolved"
exit 1
What Developers Actually See
In Their Pull Request:
Security Scan Report
SUMMARY:
45 checks passed
2 warnings (review recommended)
1 critical issue (must fix)
CRITICAL ISSUES:
────────────────────
• S3_BUCKET_PUBLIC_ACCESS_BLOCK
File: infrastructure/storage.tf:23
Issue: S3 bucket allows public access
Risk: Data breach, unauthorized access
Fix: Add 'block_public_access = true'
Business Impact: Prevents potential $2M+ breach
WARNINGS:
────────────────────
• EC2_INSTANCE_OVERSIZED
File: infrastructure/compute.tf:45
Issue: Instance type too large for workload
Current: m5.2xlarge ($0.384/hour)
Recommended: t3.medium ($0.0416/hour)
Potential Savings: $3,000/month
• IAM_POLICY_TOO_PERMISSIVE
File: infrastructure/security.tf:12
Issue: IAM policy allows '*' actions
Risk: Security breach escalation
Fix: Apply principle of least privilege
Implement Basic GitHub Action:
# .github/workflows/basic-security.yml
name: Basic Security Scan
on: [pull_request]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: tenable/terrascan-action@main
- uses: bridgecrewio/checkov-action@master
Conclusion:
What We’ve Solved:
- Financial Protection – Prevent million-dollar security incidents and cost overruns
- Compliance Assurance – Automatically enforce regulatory requirements
- Operational Excellence – Catch problems early vs. firefighting in production
- Developer Empowerment – Give immediate feedback and education
- Risk Management – Quantifiable reduction in security and operational risks