Skip to content
Back to Blog
·11 min read·technology

IaC Security Scanning: Catch Terraform Misconfigs Pre-Deploy

IaC security scanning stops Terraform misconfigurations before deploy. See how Indian teams use tfsec, Checkov and policy-as-code to gate every change.

BR

Bachao.AI Research Team

Cybersecurity Research

Scan Your Attack Surface

Security exposure this creates

Unpatched vulnerabilities in your tech stack are the #1 entry point for breaches targeting Indian businesses. Here's what to watch.

Infrastructure-as-Code security scanning means running automated policy checks against Terraform, CloudFormation, or Pulumi files before they are applied — catching a public S3 bucket, an open security group, or an unencrypted database in a pull request instead of in production. For Indian teams shipping cloud infrastructure weekly, this single control is one of the highest-leverage ways to stop the misconfiguration class of incidents that dominates cloud breach reports year after year.

Cloud misconfiguration is not a theoretical risk category — it is a leading cause of cloud security incidents across multiple industry studies, and the pattern repeats: a Terraform module gets copy-pasted from an old project, a cidr_blocks = ["0.0.0.0/0"] slips through review, and the change is applied because nothing in the pipeline stopped it. IaC scanning closes that gap by treating infrastructure definitions the way application security treats source code — scan before it merges, gate before it deploys, monitor after it runs.

Why IaC security scanning matters for Indian cloud teams

Most Indian startups and mid-market companies now provision infrastructure through code rather than console clicks. That is a security improvement in principle — every change is versioned, reviewable, and repeatable — but only if the review step actually inspects the security properties of the change. In practice, review of infrastructure pull requests tends to focus on whether the resource works, not whether it is safe. A reviewer checks that VPC peering connects; they rarely trace whether the new IAM policy grants s3: on .

This gap matters more in India because of two converging pressures: the Digital Personal Data Protection (DPDP) Act, 2023 creates direct accountability for data fiduciaries when personal data is exposed through inadequate safeguards, and CERT-In's 2022 directions require reporting of security incidents — including unauthorised access — within six hours of detection (cert-in.org.in). A misconfigured storage bucket that exposes customer data is exactly the kind of incident both regimes are built around, and it is entirely preventable at the code stage.

⚠️
WARNING
A single unreviewed Terraform apply can expose an entire data store to the internet in seconds. The exposure window starts immediately — it does not wait for your next manual cloud audit.

What IaC scanners actually check

Tools in this category — open-source options like tfsec, Checkov, and Trivy's IaC scanning mode, plus policy-as-code frameworks like Open Policy Agent (OPA) and HashiCorp Sentinel — parse Terraform HCL, CloudFormation YAML/JSON, Kubernetes manifests, and Dockerfiles into an abstract representation, then run rule sets against it. The rules map closely to known control frameworks; many scanners ship built-in mappings to CIS Benchmarks (cisecurity.org) and NIST SP 800-53 control families (nist.gov).

Typical checks include:

    1. Storage resources (S3, Azure Blob, GCS) created without public-access blocks or with world-readable ACLs
    2. Security groups or network ACLs with unrestricted ingress on sensitive ports
    3. Databases and object stores provisioned without encryption-at-rest
    4. IAM roles and policies with wildcard actions or wildcard resources
    5. Missing logging (CloudTrail, VPC Flow Logs, Cloud Audit Logs disabled)
    6. Secrets or credentials hardcoded directly in .tf files instead of a secrets manager reference
    7. Kubernetes workloads running as root or without resource limits
Policy-as-code frameworks like OPA go a step further: they let a team write custom rules specific to its own environment — for example, "no resource in the payments module may attach a role with iam:PassRole unless explicitly tagged for exception."
6 hoursWindow to report cyber incidents to CERT-In after detection (CERT-In Directions, 2022)
₹250 croreMaximum penalty ceiling for significant DPDP Act violations, incl. failure to safeguard data (MeitY, DPDP Act 2023)

Where scanning fits in the pipeline

The value of IaC scanning depends entirely on placement. A scan that only runs nightly against already-applied infrastructure tells you about a problem after it is live — useful for drift detection, but too late to prevent the initial exposure. The control that actually prevents incidents is a pre-merge, pre-apply gate.

graph TD A[Developer commits IaC change] --> B[Static IaC scan on PR] B --> C{Policy gate} C -->|Pass| D[Terraform plan review] C -->|Fail critical finding| E[Blocked - fix required] D --> F[Apply to environment] F --> G[Continuous drift and posture check] A -.->|Scan skipped or bypassed| H[Public bucket ships to prod] style A fill:#1e3a5f,stroke:#3B82F6,color:#e2e8f0 style B fill:#1e3a5f,stroke:#3B82F6,color:#e2e8f0 style C fill:#1e3a5f,stroke:#3B82F6,color:#e2e8f0 style D fill:#1e3a5f,stroke:#3B82F6,color:#e2e8f0 style E fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style F fill:#1e3d2f,stroke:#10B981,color:#e2e8f0 style G fill:#1e3d2f,stroke:#10B981,color:#e2e8f0 style H fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0

The dotted path in that diagram matters most operationally. Every team that has had an IaC-driven exposure incident has one thing in common: a way existed to bypass the scan — a hotfix branch, a manual console change, or a scanner configured to warn instead of block. The gate only works if "critical finding" actually stops the merge.

🛡️
SECURITY
Treat the policy gate as a hard block for critical and high-severity findings, not an advisory comment. If a single approving review can override the gate with no compensating control, you do not have a gate — you have a suggestion.

Know your vulnerabilities before attackers do

Run a free VAPT scan — takes 5 minutes, no signup required.

Book Your Free Scan

Policy as code vs manual checklist review

Manual review of infrastructure changes does not scale past a handful of engineers, and it is inconsistent even at small scale — the same reviewer catches a public bucket on Monday and misses an equivalent finding on Friday. Policy-as-code turns the checklist into an enforced, versioned artifact.

ApproachConsistencyScales with team sizeAudit trailCatches novel misconfig patterns
Manual PR review onlyLow — depends on reviewerPoorWeak (comments, not enforced)Sometimes, if reviewer is experienced
Nightly cloud posture scanMediumGoodGoodYes, but after resources are live
Pre-merge IaC scan (tfsec/Checkov-class)High — same rules every timeGoodStrong (CI logs, blocked PRs)Only what rule sets cover
Pre-merge scan + custom OPA/Sentinel policyHighGoodStrongYes, including org-specific rules
No single row is a complete answer. The strongest posture combines a pre-merge scanner, custom policy for org-specific rules, and a continuous drift check for resources changed outside the pipeline — more common than most teams admit.

Drift and the state-file secrets problem

Two failure modes get less attention than PR scanning but cause equal damage.

Drift is what happens when the live cloud environment no longer matches what the Terraform state file says it should be — someone made a manual console change, an automated remediation script fired, or a different pipeline touched the same resource. Drift matters for security because a resource that started compliant can silently become non-compliant, and your pre-merge scanner never sees it because no PR was ever opened. Drift detection tools re-read actual cloud state and diff it against the IaC definition, flagging exactly this gap.

State-file secrets are the quieter risk. Terraform state files frequently contain resource attributes in plaintext — database passwords, API keys, connection strings — because Terraform tracks the full attribute set of every resource it manages. If that state is stored in a bucket without encryption, or committed to a git repository (which still happens), every secret referenced anywhere in your infrastructure code sits in one flat, unencrypted-by-default file.

🚨
DANGER
Never commit a terraform.tfstate file to version control, and never store remote state without both encryption-at-rest and bucket-level access restrictions. A leaked state file can expose every credential referenced across your infrastructure in a single artifact.

The practical mitigations are well established: use a remote backend with encryption and locking, restrict state bucket access to the CI role and a small break-glass group, and treat any secret that must appear in state as a candidate for a secrets manager reference with a short-lived token instead of a static value.

🎯Key Takeaway
IaC scanning only prevents incidents if it sits before the apply step and actually blocks critical findings — a scanner that only reports after deployment, or one that can be silently bypassed, gives you visibility without prevention. Pair pre-merge scanning with drift detection and locked-down remote state to close the three gaps that account for most Terraform-driven cloud exposures: unreviewed changes, out-of-band drift, and leaked state-file secrets.

Rough distribution of what actually causes cloud incidents

Cloud security research consistently places misconfiguration at or near the top of root-cause categories for cloud incidents, ahead of exploited software vulnerabilities in the infrastructure layer itself. Exact percentage splits vary by report methodology and year, so the chart below is a qualitative, directional grouping rather than a single cited split.

pie title Cloud Incident Root Causes (Qualitative Grouping) "Misconfiguration" : 45 "Credential or identity compromise" : 25 "Vulnerable software / unpatched CVE" : 15 "Insider or third-party access" : 10 "Other" : 5

The consistent finding across cloud providers, CSA (Cloud Security Alliance), and incident response vendors is directional agreement, not identical numbers: misconfiguration is the single largest bucket, and the one most within an engineering team's direct control. You cannot fully eliminate credential theft through IaC scanning, but you can eliminate "we shipped a public bucket by accident" incidents with a properly enforced pipeline gate.

Building this into an Indian engineering workflow

Rolling out IaC scanning does not require a large security team. A pragmatic sequence for most Indian engineering orgs:

  1. Start in report-only mode — run scanning in CI without blocking merges for one to two sprints, so the team can tune out false positives first.
  2. Set a severity threshold for blocking — critical and high findings block the merge; medium and low are logged but do not stop the pipeline initially.
  3. Add custom policy for high-risk patterns your team has gotten wrong before, encoded as an OPA or Sentinel rule.
  4. Add scheduled drift detection against production state, since drift cannot be caught at merge time.
  5. Lock down remote state with encryption, restricted IAM access, and locking before scaling to more repositories.
  6. Review findings monthly — rule sets change, and a threshold set correctly in January can be stale by next quarter.
This is also where independent verification earns its keep: an internal gate reduces misconfiguration significantly, but a periodic external check — a broader vulnerability assessment covering cloud configuration alongside application and network testing — catches gaps a single tool misses, including issues from console changes or resources outside your Terraform codebase.

Bachao.AI runs automated vulnerability assessment and penetration testing for Indian companies, including cloud configuration checks that complement — not replace — an IaC pipeline gate, and where CERT-In empanelled reporting is required, that is delivered with a CERT-In empanelled partner. For teams building a DPDP-aligned security program, cloud misconfiguration controls are one of several safeguards worth documenting; see the DPDP compliance overview for the broader control set. Dhisattva AI Pvt Ltd built the platform to make continuous, automated checking accessible without a dedicated in-house security team.

If your pipeline does not currently block on critical IaC findings, that is the highest-leverage gap to close first — before adding scanning tools on top of a pipeline that cannot enforce what it finds. A free VAPT scan will also flag already-live cloud misconfigurations sitting in production today. For more, browse the blog.

Frequently Asked Questions

What is IaC security scanning?
IaC security scanning is automated analysis of infrastructure-as-code files — Terraform, CloudFormation, Pulumi, Kubernetes manifests — against security rules before that code is applied to a live environment. It catches public buckets, open network access, and missing encryption at the code-review stage instead of after deployment.
What is the difference between tfsec, Checkov, and OPA?
tfsec and Checkov are static scanners that check IaC files against built-in rule libraries mapped to frameworks like CIS Benchmarks. Open Policy Agent (OPA) is a general-purpose policy engine for custom rules beyond the built-in set, typically used alongside a scanner rather than instead of one.
Can IaC scanning fully replace a cloud security audit?
No. IaC scanning only catches issues present in code that goes through your pipeline — it cannot see manual console changes, drift, or resources created outside your Terraform codebase. Pair it with drift detection and periodic independent assessment for full coverage.
Why does the Terraform state file matter for security?
Terraform state files often contain resource attributes in plaintext, including passwords and connection strings, because Terraform must track every attribute of every managed resource. An unencrypted or publicly accessible state file can expose every credential referenced in your infrastructure code.
Is cloud misconfiguration really a major cause of security incidents?
Yes. Multiple industry studies, including research referenced by the Cloud Security Alliance, identify misconfiguration as a leading root cause of cloud security incidents, generally ahead of exploited software vulnerabilities in the infrastructure layer.
Does CERT-In require reporting cloud misconfiguration incidents?
CERT-In's 2022 directions require reporting of specified cyber security incident categories, including unauthorised access to systems or data, within six hours of detection. A misconfiguration leading to unauthorised data access falls within that obligation. See cert-in.org.in for the full list of reportable categories.
BR

Bachao.AI Research Team

Cybersecurity Research

AI-powered security research and threat intelligence from the Bachao.AI team. Covering the latest vulnerabilities, CVEs, and cybersecurity developments affecting Indian businesses.

Get cybersecurity insights for Indian SMBs

Weekly vulnerability alerts, DPDP compliance tips, and security guides. No spam — unsubscribe anytime.

We respect your privacy. Your email is never shared.

Find out if you're exposed to this class of threat

Free automated scan — risk score in under 2 hours. No credit card required.

Scan Your Attack Surface
Find your vulnerabilitiesStart free scan →