Compliance as Code: Cloud-Native DevOps 2026
#complianceascode#devsecops#cloudsecurity#devops#infrastructureascode
Unlock efficient compliance as code for cloud-native DevOps. Discover key benefits, essential tools like OPA & Sentinel, plus your strategic adoption roadmap.

Two weeks before an audit, the engineering calendar usually tells the story. Platform teams stop backlog work. Security asks for screenshots. DevOps engineers dig through Terraform repos to prove a control existed at a point in time. Someone exports cloud settings into a spreadsheet that's out of date before the meeting ends.
That workflow feels normal in a lot of organizations. It shouldn't. Modern cloud delivery moves too quickly for quarterly evidence hunts and point-in-time reviews. If your infrastructure is defined in code, changed through pull requests, and deployed through pipelines, your compliance model has to live in the same system.
From Audit Dread to Automated Assurance
The hard part about traditional compliance isn't only effort. It's timing. Teams usually discover control failures after the change is already merged, deployed, and connected to production dependencies. That turns a small configuration mistake into a larger remediation project, usually under deadline pressure.
The market hasn't fully made the shift yet. According to the 2025 State of Continuous Controls Monitoring Report summarized by the Cloud Security Alliance, only 46% of CISOs have begun implementing compliance as code. The same source notes that a global telecommunications company that integrated compliance as code into its CI/CD pipeline achieved $1.8 million in savings and 2,000 person-hours saved in the first year alone.
Why the old model keeps failing
Manual compliance breaks in predictable ways:
- Evidence arrives late: Teams collect proof after deployment, not at the point of change.
- Ownership gets blurred: Security writes requirements, platform teams interpret them, and auditors evaluate the result long after context is lost.
- Fixes cost more: A policy violation caught in production usually means rollback coordination, emergency review, and rework across multiple teams.
Practical rule: If a control can be expressed as a build check, waiting for an audit to verify it is wasted effort.
Compliance as code changes the sequence. Instead of asking, “Was this environment compliant last quarter?” the better question becomes, “Was this change allowed to ship without meeting the rule?” That's a much stronger operating model because it ties governance directly to delivery.
This is also where broader compliance-driven security modernization becomes useful. The strongest programs don't treat compliance as a reporting layer bolted onto engineering. They use it to modernize delivery practices, standardize controls, and reduce ad hoc exceptions.
What the shift looks like in practice
In a mature setup, a policy sits next to infrastructure code. A pull request triggers automated evaluation. Non-compliant changes fail early. Approved changes produce evidence automatically through pipeline logs, attestations, and version history. Audit prep gets shorter because much of the evidence already exists.
That same pattern is why a technical review should include policy automation readiness, not only architecture quality. A due diligence exercise such as this technical due diligence checklist is far more useful when it asks whether controls are enforceable in code, not merely documented in a wiki.
The business value is straightforward. Less audit scramble. Less drift. Fewer late surprises. Faster delivery with clearer guardrails.
The Core Principles of Compliance as Code
Compliance as code is easiest to understand if you treat it like a linter for infrastructure and operations. A linter checks source code for rules before bad patterns spread. Compliance as code does the same for cloud resources, deployment manifests, identity settings, and runtime configurations.
It isn't one product. It's an operating model built on three properties: automated, versioned, and testable.

Automated, versioned, testable
Automation matters because manual interpretation introduces inconsistency. Versioning matters because controls change, and you need to know who changed a rule, why, and when. Testability matters because an untested policy can block valid deployments just as easily as it can catch bad ones.
A strong infrastructure foundation makes this much easier. Teams that already follow disciplined infrastructure as code best practices usually adapt faster because they already manage cloud state through repositories, reviews, and pipelines.
For technical controls, the upside is substantial. According to Contino's compliance as code guidance, 70-90% of technical controls for frameworks such as SOC 2 and ISO 27001 can be fully automated with compliance as code, and audit preparation can drop from over 100 hours per quarter to near-zero when machine-attested logs are used as evidence.
Prevent, detect, remediate
The most useful mental model is the prevent, detect, remediate triad.
Prevent
Prevention stops non-compliant changes before they become infrastructure. A common example is a policy that blocks creation of a public S3 bucket or rejects a Terraform change that omits required encryption settings. This is the cheapest place to enforce a rule because the fix is still local to the change request.
Detect
Detection watches what's already running. Even well-managed environments drift. Someone can change a setting manually in the cloud console. A temporary exception can remain in place after the incident is over. A detector compares the live estate to the expected policy and raises a signal when they diverge.
Prevention without detection leaves you blind to drift. Detection without prevention leaves you fixing the same class of problem repeatedly.
Remediate
Remediation closes the loop. Sometimes that means opening a ticket with the exact failing resource and policy reference. Sometimes it means automated correction, such as re-enabling required logging or restoring an approved baseline. The best remediation paths are selective. Auto-fix safe controls. Escalate risky changes to humans.
A concrete policy example
Take an S3 encryption rule expressed in OPA-style logic. The policy checks incoming infrastructure definitions. If a bucket lacks server-side encryption, the build fails before merge. That's not abstract governance. It's a guardrail with an immediate engineering outcome.
The same principle applies across cloud-native systems:
- Terraform: validate encryption, tags, network boundaries, and logging before apply
- Kubernetes: reject workloads missing security context, approved registries, or policy labels
- Cloud configs: scan identity, storage, and audit settings continuously in live accounts
What works is clarity. Good policies are narrow, understandable, and mapped to specific control intent. What fails is writing giant, opaque rule sets that try to encode every exception from day one.
Mapping Automation to Key Regulations
Regulatory frameworks often look overwhelming because they're written for governance, not for pipelines. The practical move is to break each framework into technical control statements and then decide which of those can be enforced automatically during build, deploy, and runtime.

PCI DSS in cloud delivery
For PCI-oriented environments, one high-value target is protection of sensitive cardholder data through encryption and tightly controlled infrastructure settings. In practice, that means policies that reject unencrypted storage, disallow public exposure of payment-related services, and verify logging is enabled for systems that process or transmit payment data.
A compliance rule in this context doesn't “make you PCI compliant.” It enforces a technical requirement that supports PCI objectives. That distinction matters. Code can enforce the control. People still have to own the broader program.
HIPAA in operational terms
HIPAA work becomes clearer once you translate it into specific safeguards on systems that handle ePHI. Typical enforcement points include audit logging, access restrictions, encryption, and retention of evidence that shows those protections stayed enabled.
A practical pattern is to codify rules that require logging on databases and application components tied to protected health data. If a service is deployed without the required telemetry or if a storage component doesn't meet encryption policy, the pipeline blocks the release or flags the live drift.
Good compliance as code starts with control intent. The rule should answer one question clearly: what condition must always be true?
SOC 2 and access control evidence
SOC 2 often exposes a gap between policy statements and operational proof. Teams may say access is reviewed and least privilege is enforced, but the evidence is scattered across tickets, screenshots, and exports.
Compliance as code helps by turning parts of that story into repeatable checks:
- Identity guardrails: ensure MFA-related settings and logging controls remain enabled where technically enforceable
- Access boundaries: verify infrastructure roles and service permissions follow approved patterns
- Change evidence: tie approvals, pull requests, and deployment records to the exact policy version applied at the time
That kind of evidence is stronger than after-the-fact documentation because it's produced as a side effect of delivery, not assembled later.
For organizations that also answer to financial control obligations, security and governance requirements frequently overlap. That's one reason a broader view of Sarbanes-Oxley cyber security considerations is useful. Even when the frameworks differ, the implementation pattern is often similar: codify baseline controls, enforce them consistently, and preserve evidence automatically.
What should stay manual
Not every requirement belongs in code. Narrative policy reviews, risk acceptance decisions, exception governance, and certain approval workflows still require human judgment. Trying to automate those prematurely usually creates brittle processes and false confidence.
A better split looks like this:
| Regulation area | Best automation target | Better left to human review |
|---|---|---|
| PCI-oriented cloud controls | Encryption, logging, network exposure checks | Scope interpretation, compensating controls |
| HIPAA safeguards | Logging, access restrictions, baseline config enforcement | Privacy decisions, procedural reviews |
| SOC 2 technical evidence | Change records, system settings, control attestations | Board-level governance, policy approval narratives |
The useful question isn't whether a framework can be automated end to end. It's which control statements can become executable checks without losing their meaning.
Architectures and Common Integration Points
Most compliance as code programs succeed or fail based on placement. If the policy engine sits only at the end of the process, teams still discover issues too late. If checks run only on developer laptops, there's no reliable enforcement. The right design layers controls across the delivery lifecycle.

Start before the pipeline
The earliest integration point is local development. Pre-commit hooks and repo-level validation catch obvious issues before a pull request exists. This isn't the final gate, but it improves feedback speed and reduces noisy CI failures.
For Terraform repositories, local checks can validate formatting, scan for banned resource patterns, and run policy tests against changed modules. For Kubernetes repos, developers can validate manifests before they ever hit the cluster admission layer.
Cloud-native teams that already build around cloud-native application development usually have a natural place for these checks because delivery is already standardized around declarative definitions and automated promotion paths.
CI as the first hard gate
The CI pipeline is where compliance as code usually starts paying off. Here, policy evaluation becomes mandatory, reproducible, and tied to versioned changes.
A practical example comes from Orbiq's developer guide to compliance as code. In a typical CI/CD pipeline, a rule can scan Terraform files before deployment. If an AWS EBS volume lacks the encrypted: true attribute, the pipeline can automatically fail the build and stop the infrastructure from being created.
That pattern generalizes well:
- Terraform plan stage: inspect planned resources for encryption, tags, IAM constraints, logging, or network policy
- Container build stage: validate image provenance, base image rules, or required metadata
- Manifest validation stage: enforce Kubernetes security standards before deployment artifacts are approved
Admission control at runtime boundaries
CI catches intended changes. Runtime enforcement catches what reaches the platform boundary. In Kubernetes, admission controllers are the most common control point. They inspect incoming resource definitions and either allow or reject them.
That's where rules such as “only signed images from approved registries” or “production workloads must include required security settings” become enforceable in real time. This layer matters because it provides a final guardrail even if an upstream process is bypassed or misconfigured.
Here's a simple explanation:
- Developers get early feedback locally
- CI enforces policy on proposed changes
- Admission control enforces policy at deployment time
- Production monitoring checks that reality still matches intent
Continuous monitoring in production
Production is where drift shows up. Emergency console changes, one-off fixes, expired exceptions, and service-specific quirks all create differences between the approved state and the running state.
Continuous monitoring tools evaluate the live environment against policy and produce alerts or remediation actions. In cloud environments, this often includes scanning for disabled logging, overly broad permissions, public storage exposure, or unapproved resource changes.
The strongest architecture doesn't trust any single checkpoint. It assumes some changes will slip past one layer and makes the next layer catch them.
What works and what doesn't
The implementation pattern that works is progressive enforcement. Start with policies that are easy to understand and hard to argue with. Enforce encryption, logging, approved registries, and obvious exposure rules first. Run noisier or more context-heavy policies in audit mode until the false positives are under control.
The pattern that fails is dropping a large policy bundle into production and blocking every team at once. That turns compliance as code into a credibility problem. Engineers stop seeing it as a quality system and start seeing it as an arbitrary gate.
Good architecture gives each layer a different job. Local tools guide. CI blocks bad changes early. Runtime controls protect the platform boundary. Production scanning watches for the inevitable gap between what was approved and what still exists.
A Survey of Leading Tools and Frameworks
Tool choice matters less than policy design, but it still shapes developer experience, operating overhead, and how broadly you can reuse rules. A universal platform is not typically needed on day one. Instead, what's required is a toolkit that fits the stack and keeps control logic understandable.
A useful split is this: some tools are strongest at pre-deployment policy evaluation, some at runtime cloud enforcement, and some at infrastructure testing.
OPA and Gatekeeper
Best for: universal, decoupled policy across multiple systems
Open Policy Agent (OPA) is the most flexible option when you want one policy language applied across Terraform checks, Kubernetes admission, API authorization, and custom workflows. Gatekeeper packages OPA for Kubernetes admission control and gives teams a native way to manage constraints inside clusters.
A stripped-down example in Rego might deny a public bucket or reject a workload missing required labels. The strength is expressive logic. The cost is learning curve. Rego is powerful, but teams need discipline to keep policies readable.
Short example:
deny[msg] {
input.kind == "Deployment"
not input.metadata.labels.owner
msg := "owner label is required"
}Choose OPA when policy needs to travel across environments. If your organization wants one rule model across cloud infrastructure, Kubernetes, and service-level decisions, OPA is usually the better fit.
Teams evaluating policy ecosystems often also compare them with broader GRC platforms. If you're sorting through adjacent governance tooling, this review of leading governance, risk, and compliance software is useful context because it highlights where workflow tools complement, rather than replace, engineering-native policy enforcement.
For deeper OPA-specific implementation work, this Open Policy Agent guide is a solid companion if you're building around Rego and admission control patterns.
HashiCorp Sentinel
Best for: organizations already standardized on Terraform Cloud or other HashiCorp workflows
Sentinel works well when your infrastructure lifecycle already runs through HashiCorp tooling. The big advantage is proximity. Policies evaluate directly in the same workflow where infrastructure plans are created and reviewed.
That reduces plumbing. It also keeps policy decisions closer to the IaC process teams already use. The trade-off is ecosystem concentration. Sentinel is excellent inside the HashiCorp path, but less universal if you want one engine spanning many unrelated systems.
Chef InSpec
Best for: validating infrastructure state and generating test-style compliance evidence
InSpec feels familiar to teams that like a testing mindset. Instead of only writing admission policies, you write controls that verify systems meet expected conditions. It's especially useful for host, OS, and environment validation where the question is “does this running system satisfy the requirement?”
Example style:
describe file('/etc/example.conf') do
it { should exist }
endInSpec is a strong fit when your environment includes both cloud-native services and more traditional infrastructure that still needs formal control verification.
Cloud Custodian
Best for: runtime governance and cloud resource remediation
Cloud Custodian shines after deployment. It monitors cloud resources and can take action when they violate policy. If a storage resource is publicly exposed or a required control is missing, Cloud Custodian can notify, tag, quarantine, or remediate depending on the rule.
That makes it a good complement to Terraform and CI enforcement. Pre-deployment tools stop bad intent. Custodian handles cloud reality.
Compliance as Code tool comparison
| Tool | Primary Use Case | Policy Language | Integration Point |
|---|---|---|---|
| OPA | Cross-platform policy enforcement | Rego | CI pipelines, APIs, custom services |
| Gatekeeper | Kubernetes admission control | Rego with constraint model | Kubernetes clusters |
| HashiCorp Sentinel | Policy for Terraform-centric workflows | Sentinel language | Terraform planning and apply workflows |
| Chef InSpec | Infrastructure compliance testing | Ruby-based DSL | Host validation, environment testing, audit evidence |
| Cloud Custodian | Runtime cloud governance and remediation | YAML policies | Live cloud accounts and services |
How to choose without overengineering
Start from the control point, not the brand name.
If your biggest issue is Terraform drift and unsafe infrastructure plans, begin with a policy engine in CI and your provisioning workflow. If your biggest issue is Kubernetes workload standards, admission control belongs first. If the problem is cloud sprawl and unmanaged exceptions, runtime governance tools deserve priority.
A simple selection lens helps:
- Need one reusable policy language across systems: OPA
- Need Kubernetes-native admission control quickly: Gatekeeper
- Live in Terraform Cloud workflows: Sentinel
- Need test-oriented infrastructure verification: InSpec
- Need runtime cleanup and response: Cloud Custodian
Don't buy a tool to “do compliance as code.” Pick the enforcement point that fixes your most expensive failure pattern first.
The teams that struggle usually make one of two mistakes. They either choose an advanced platform before they know which controls matter, or they scatter policies across too many engines with no ownership model. Keep the first implementation narrow. One repository. One policy path. One accountable team.
Implementation Patterns and Governance
The hardest part of compliance as code usually isn't writing the first policy. It's building a program that teams trust, auditors can follow, and engineers won't route around.
Too many initiatives stall because they start with a giant framework mapping exercise and no operating model. Others fail because a security team writes rules in isolation, then drops them into pipelines with no testing or exception process.

The operational problem to solve
Manual governance is still ingrained in most environments. A GARP survey on modern compliance operations found that over 50% of compliance leaders still rely on manual, spreadsheet-driven processes. The same source notes that post-deployment drift affects 60% of IaC estates without continuous scanning, and that early detection via compliance as code tools can cut remediation costs by up to 70%.
Those numbers point to the issue. The problem isn't just documentation overhead. It's that manual controls don't hold up once cloud environments change continuously.
A phased rollout that actually works
The most reliable adoption model is phased and boring. That's a good thing.
Phase one builds credibility
Pick a narrow scope. One cloud account group, one platform domain, or one application class. Target controls that are technical, high-signal, and easy to explain. Encryption, required logging, blocked public exposure, and approved image sources are good starting points.
Use audit mode first where possible. Let teams see violations. Tune false positives. Fix the messaging before you enforce.
Phase two standardizes the pipeline
Move validated policies into the main delivery path. Store them in Git. Review policy changes through pull requests. Version them explicitly. Tie each rule to a control statement or internal standard so nobody has to guess why it exists.
This is also where policy testing becomes mandatory:
- Unit tests: validate policy logic against known good and bad examples
- Integration tests: run policies in a staging pipeline with representative infrastructure definitions
- Regression tests: keep old edge cases in the test suite so fixes don't reintroduce noise
Phase three expands ownership
Once the first control set is stable, expand by domain instead of by framework. Add network policies, identity policies, logging baselines, then runtime drift detection. Let subject matter owners contribute, but keep one approval model for policy publication.
A practical governance split often works best:
| Responsibility | Typical owner |
|---|---|
| Control intent and risk interpretation | Security and compliance leads |
| Policy implementation and test harnesses | Platform or DevSecOps engineers |
| Exception approval | Designated governance group |
| Pipeline integration and release safety | Platform engineering |
Avoiding compliance theater
Compliance as code can still become theater if teams treat policies like static artifacts. If nobody versions them, tests them, or reviews exceptions, you've only moved the paperwork into YAML and Rego.
The antidote is operational discipline.
- Version every policy: controls should have history, approvals, and rollback capability
- Record every evaluation outcome: pass, fail, override, and exception decisions should be auditable
- Limit exception paths: make them explicit, time-bound, and visible
- Review policy noise: if a rule creates recurring confusion, fix the rule or the developer guidance
A policy that engineers constantly bypass is not an effective control. It's evidence that the implementation doesn't match reality.
Measuring whether the program is healthy
Early measurement often prioritizes an ineffective metric, specifically, counting policies. That tells you almost nothing.
Better indicators are operational:
- Percentage of technical controls automated
- Volume and type of policy failures
- Time to remediate drift
- Frequency of exception requests
- Repeat violations by team or service class
Use those metrics to answer practical questions. Are teams hitting the same preventable issue every week? Are runtime checks finding drift that CI should have stopped? Are exceptions concentrated around one poorly designed rule?
The strongest programs also keep evidence generation close to delivery events. Pull request approvals, CI logs, attestation artifacts, policy version history, and deployment metadata should feed an audit trail automatically. If a team still needs a manual screenshot chase for basic controls, the implementation is incomplete.
What small and mid-sized teams should do differently
Smaller organizations often try to copy large-enterprise control catalogs too early. That usually backfires. They end up with more policy surface area than they can maintain.
A better approach is selective coverage:
- Start with the controls that map directly to the biggest operational risk.
- Reuse managed services where possible instead of writing custom policy around everything.
- Keep the first implementation in one platform lane, usually Terraform or Kubernetes, not both if the team is small.
- Add runtime scanning only after the CI path is stable.
That sequence builds trust. It also makes the eventual business case much easier because the team can point to reduced manual effort, fewer late fixes, and cleaner audit evidence tied to actual engineering workflows.
Conclusion The Future of Automated Governance
Compliance as code is a shift in operating model, not a rebranding of security checks. It moves control enforcement to the same place where infrastructure changes already happen: repositories, pull requests, pipelines, admission controllers, and runtime scanners.
That shift matters because cloud systems don't stay still. A static document can describe the desired state. It can't enforce it. A spreadsheet can track an exception. It can't stop an unsafe deploy. Code can.
The practical path is clear. Start with technical controls that are easy to codify. Put them in version control. Test them like application logic. Enforce them progressively. Collect evidence as a byproduct of delivery instead of as a separate audit project.
The long-term payoff is bigger than passing the next review. Teams with strong compliance as code foundations are better prepared for multi-cloud governance, tighter customer security requirements, and AI-enabled delivery workflows that increase change velocity even further. If you're adopting generative AI in engineering, that pressure only goes up. More generated code and more automated infrastructure changes require stronger machine-enforced guardrails, not weaker ones.
The organizations that treat compliance as code as a strategic engineering capability will move faster with fewer surprises. The rest will keep paying the audit tax every quarter.
If your team is trying to operationalize compliance as code across Terraform, Kubernetes, CI/CD, or cloud governance workflows, Pratt Solutions can help design the policy architecture, implementation roadmap, and automation model that fits your environment without slowing delivery.