Somewhere in your organization there is a spreadsheet. It has columns for control ID, control description, evidence, owner, and status. Once a quarter, or maybe once a year, someone opens it, updates a few rows, attaches some screenshots, and marks things "compliant." An auditor reviews it, asks a few questions, and signs off. Everyone breathes a sigh of relief and goes back to their actual work. This is compliance as theater.
The spreadsheet says encryption at rest is enabled on all databases. Whether that's true right now, on every database instance in every environment, nobody knows. The spreadsheet was accurate when someone checked three months ago. Since then two new databases were provisioned, a staging environment was rebuilt, and a developer spun up a test instance with default settings. The posture the spreadsheet documents started drifting from reality the moment someone closed the file.
The Drift Problem
Compliance drift is the gap between your stated security posture and your actual one. It always happens, and the only open questions are how fast and how far. In any environment with more than a handful of resources, a manual compliance check is a sample at best: you check a subset of resources at one point in time and conclude that everything is fine. It's like checking the temperature in one room and assuming the whole building's HVAC is working.
Infrastructure changes continuously, and compliance validation happens periodically. Resources are created, modified, and destroyed every day. Configurations shift and new services come online. Old services get deprecated but not decommissioned. IAM policies accumulate permissions like sediment. Security groups get "temporary" rules that become permanent. Each of these changes is a potential violation that won't be detected until the next audit cycle, if it's detected at all.
This isn't a people problem, and your engineers aren't malicious. They work at a pace manual compliance processes can't match. Nobody deploying a fix for a production issue at 2 AM is thinking about whether the new security group rule satisfies control AC-4 in your compliance framework. They're thinking about getting the service back up. The violation is a side effect of velocity, and velocity is not going to slow down.
Policy as Code
The answer is to enforce compliance continuously and stop reviewing it periodically. Write your compliance policies as code: testable, versionable, executable code that runs against your actual infrastructure and tells you in real time whether you're compliant.
Tools like Open Policy Agent (OPA), HashiCorp Sentinel, AWS Config Rules, and Azure Policy make this possible today. Where the spreadsheet has a row that says "all S3 buckets must have encryption enabled," you write a policy that evaluates every S3 bucket in your account and flags any without encryption configured. Where it has a quarterly check that says "no public-facing databases," you write a rule that evaluates every RDS instance's network configuration and blocks or alerts on any that are publicly accessible.
A spreadsheet tells you what should be true, needs a person to verify it, and can be wrong for months without anyone knowing. Code tells you what is true, verifies it automatically and continuously, and fails loudly as soon as something is off.
A simple OPA policy that enforces encryption at rest looks like this:
deny[msg] {
resource := input.resource.aws_db_instance[name]
not resource.storage_encrypted
msg := sprintf("RDS instance '%s' does not have encryption at rest enabled", [name])
}
Those five lines are your compliance control. You can test them, keep them in version control, and run them in CI. They never forget to check, never get the check wrong because they're tired or distracted, and never skip a resource because they didn't know it existed.
Compliance in the Pipeline
Detection is useful, but prevention is where compliance as code pays off most. When the policies run in your CI/CD pipeline, violations are caught before they reach production. A developer writes a Terraform plan that creates an unencrypted database. The pipeline runs the compliance policy suite, the policy fails, and the deployment is blocked. The developer finds out right away what's wrong and how to fix it.
Compare that with the traditional model, where an auditor finds the violation six months later and generates a remediation ticket. In the pipeline, the violation is caught where it starts, and the developer fixes it while they still have full context. There's no ticket, no remediation sprint, and no finding sitting in a tracking system for weeks while everyone argues about priority.
There's a psychological benefit too. Compliance enforced in the pipeline is part of the development workflow, where the audit was something imposed from outside. Developers internalize the constraints. They stop creating unencrypted databases because they know the pipeline will reject them, and fear of an audit finding has nothing to do with it. Compliance turns into a habit.
The pipeline should enforce policy at several points:
- Pre-commit hooks catch obvious violations locally, before code enters the pipeline. The feedback is fast and the overhead is low.
- Plan-time validation evaluates Terraform plans, CloudFormation templates, or Kubernetes manifests against policy before any resources are created.
- Deploy-time gates are the final validation before changes hit production, and your last line of defense.
- Runtime monitoring evaluates live infrastructure continuously. It catches drift from manual changes, out-of-band modifications, and resources created outside the pipeline.
Each layer catches what the one before it missed. Defense in depth applies to compliance enforcement as much as to network security.
Audit Trails That Write Themselves
Evidence collection is one of the most painful parts of compliance. Every audit requires documentation proving that controls are in place and operating effectively. In a manual process that means screenshots, exported configurations, email chains, and signed attestations, and someone spends days, sometimes weeks, assembling them before every audit.
When compliance is code, the audit trail generates itself. Every policy evaluation produces a result, pass or fail, with details. Every pipeline run is logged, every remediation is tracked in version control, and every exception has a documented approval. Nobody assembles the evidence afterward, because the system produces it as it runs.
Your auditor asks, "Can you show me that encryption at rest is enabled on all databases?" You answer with the policy code, the CI results from the last thousand pipeline runs, and the runtime monitoring dashboard that checks every 15 minutes, and you no longer have to hope a spreadsheet is current. That evidence covers everything, continuously, up to today. The spreadsheet was a point-in-time sample from three months ago.
The relationship with the auditor changes as well. The old version is an adversarial game in which you try to prove compliance after the fact. The new one is a plain demonstration of a working system. Auditors appreciate this, the good ones anyway. They'd rather review a well-designed automated system than wade through screenshots and spreadsheets.
Making Frameworks Executable
SOC 2, HIPAA, PCI DSS and FedRAMP define controls. They say what has to be true and leave the implementation to you. Most organizations fail at the translation from framework control to enforceable policy, because they translate controls into documentation when they should translate them into code.
Take SOC 2's CC6.1, logical and physical access controls. The traditional approach is to write an access control policy document, implement it by hand, and hope everyone follows it. The code approach is to define IAM policies that enforce least privilege, write OPA rules that validate those policies, run them continuously, and alert on any violation. It's the same control with a far higher level of assurance.
The mapping between frameworks and policy code doesn't have to be one-to-one. A single automated policy can satisfy several controls across several frameworks. An encryption-at-rest policy satisfies controls in SOC 2, HIPAA, and PCI at once. This is one of the less obvious savings of compliance as code: you build once and map to many frameworks, and adding a new compliance requirement becomes a tagging exercise where it used to be an implementation project.
The Regulatory Burden Is Real
I'm not going to pretend compliance is fun. The regulatory burden on engineering teams is significant and growing: new frameworks, new requirements, new audits. The temptation is to treat it as a tax, do the minimum, check the boxes, and move on. I understand that impulse. I've felt it myself.
The burden is only crushing when the work is manual. When compliance is automated, a new framework requirement means writing a new policy rule, adding it to the test suite, and mapping it to the relevant controls. You don't hire another compliance analyst, run another month-long audit prep sprint, or start another spreadsheet.
Organizations that invest in compliance automation pass audits more easily and also more cheaply. The first framework is the most expensive to automate, because you're building the infrastructure. The second is half the cost, and the third is a fraction. By the time you maintain compliance across four or five frameworks, the marginal cost of adding another is minimal. Organizations doing this manually see their compliance costs rise linearly with each new requirement.
Exceptions and Pragmatism
Some compliance controls can't be fully automated, and some policy violations shouldn't block a deployment. A rigid system that blocks every deployment on every minor deviation will be routed around. Engineers will find ways to bypass it, and you'll be worse off than before.
Build an exception process into the system. Some violations are acceptable with documentation and approval. A development environment might not need the same encryption controls as production, and a short-lived test resource might not need full compliance. What matters is that exceptions are tracked, time-bounded, and reviewed. An exception with an expiration date and an owner is manageable. Without those, it's a vulnerability you've chosen to ignore.
The policy code should support this. Tag resources that have approved exceptions. Log each exception with its justification, approver, and expiration, and automatically flag the ones that have expired. The exception process then stops being a paper trail and becomes a workflow you can enforce.
Where to Start
If you're sitting on a pile of compliance spreadsheets right now, don't try to automate everything overnight. Start with the controls that matter most and drift most often.
- Identify your 10 most critical controls. These are the ones that would cause the most damage if violated: encryption, access control, network segmentation, logging.
- Express each as a testable policy. Use OPA, Sentinel, AWS Config, or whatever fits your stack. The policy should evaluate your actual infrastructure and not a sample of it.
- Run them in CI as warnings first. Don't block deployments immediately. Gather data on how often violations occur and what the false positive rate looks like.
- Promote them to blocking enforcement. Once you trust the policies and teams have adapted, make them gates. No deployment proceeds with a compliance violation unless there's an approved exception.
- Add runtime monitoring. Policies in CI only catch changes that go through the pipeline. Runtime monitoring catches the rest: manual console changes, API calls that bypass the pipeline, drift from any source.
Compliance that exists only in a spreadsheet is a story you tell auditors. Real compliance is a property of the system: continuously verified, automatically enforced, and always current.
The organizations that get this right treat compliance as a property of their infrastructure, like availability or performance, and as part of engineering. It's built into the system, tested continuously, and monitored in real time. The spreadsheet and the quarterly fire drill are gone. What's left is a system that is provably compliant at every moment because it can't be otherwise, whether or not anyone checked.