Policy as Code vs. Compliance as Code
What you'll learn: How policy enforcement and compliance validation differ in cloud governance architectures.
The Core Distinction
While these terms sound similar and often overlap, they serve different purposes in cloud governance:
Policy as Code is about prevention and enforcement. It defines rules that actively block or allow actions in real-time. Think of it as a bouncer at a door—it stops violations before they happen. Policies might prevent launching EC2 instances without encryption, block public S3 buckets, or require specific tags on resources.
Compliance as Code is about detection and validation. It continuously scans your existing environment against compliance frameworks (like SOC 2, HIPAA, or GDPR) and reports gaps. Think of it as a safety inspector—it checks what's already there and flags issues for remediation.
The Analogy
Imagine building safety:
- Policy as Code = The door lock that won't let you enter without a valid keycard
- Compliance as Code = The monthly fire marshal inspection that checks if exit signs work and fire extinguishers are current
When Each Applies
Policy as Code runs at deployment time or infrastructure change events. Tools like AWS Service Control Policies, Azure Policy (deny assignments), or Open Policy Agent enforce rules during resource creation.
Compliance as Code runs continuously or periodically, scanning existing infrastructure. Tools like AWS Config Rules, Azure Policy (audit mode), or cloud security posture management platforms validate compliance state and generate evidence for auditors.
Working Together
Modern cloud governance uses both: policies prevent obvious violations proactively, while compliance checks catch drift, configuration changes, and nuanced requirements that need human review.
Key Takeaway: Policy as Code enforces rules to prevent violations; Compliance as Code validates and reports on compliance state—both are essential layers in a defense-in-depth governance strategy.