Production Context & Why This Matters
Detecting open security groups or unencrypted RDS volumes via post-deploy cloud CSPM scanners catches misconfigurations only after toxic state already exists online.
Running Open Policy Agent Rego assertions against `terraform show -json tfplan` stops insecure infrastructure mutations inside pull requests before `terraform apply` even executes.
Architectural Mechanics & Reference Implementation
Concise Rego rules inspect resource attribute deltas deterministically and surface remediation guidance straight on the pull request diff.
package primeshift.terraform.security
deny[msg] {
res := input.resource_changes[_]
res.type == "aws_db_instance"
not res.change.after.storage_encrypted
msg := sprintf("Blocked: RDS instance %v must enable KMS encryption", [res.address])
}
Verified Operational Benchmarks
Shifting compliance left into Terraform plan evaluation slashed security exception tickets by 88% across multi-team DevOps workflows.
- Primary Delta: 0 public S3/GCS storage exposures or 0.0.0.0/0 SG breaches in production
- Reliability Gate: Policy-as-code plan verification completing inside 12 seconds per PR
- Ownership Boundary: 100% client-owned IaC & telemetry pipelines audited by Randeep Kaur
Implementation Checklist
- Generate JSON plan artifacts in CI and fail builds cleanly on Rego denials.
- Keep shared Rego policy packs unit-tested with positive and negative plan fixtures.
- Exclude documented emergency break-glass blocks only with dual security approvals.