← ResourcesDEVOPS Β· DRIFT

Drift detection and infrastructure compliance

Native AWS tools and an automated correction loop to keep code faithful to production reality.

STRALYA13 min readAugust 2026

Why drift detection is critical in cloud infrastructure

When an AWS infrastructure grows beyond the hand-crafted stage, it crosses a critical threshold: the code becomes the single source of truth (this is what we call Infrastructure as Code, or IaC). Yet on most teams, the real state in production gradually diverges from what is declared. A developer manually adds a security rule that never makes it into the code. An operator tweaks a database parameter to resolve an urgent issue, then forgets to update the declaration. An environment variable changes without a trace. These gaps, or "drifts," pile up silently. When the time comes for a compliance audit, a cloud cost reduction, or simply a redeployment of the infrastructure after an incident, you discover that the code no longer reflects reality. The result is chaos: ad hoc remediation scripts, attempts to retroactively rewrite the code from what exists (cloud janitor work), or worse, forgotten configurations that linger in production long after they became obsolete. Automated drift detection is therefore far more than a matter of tidiness. It becomes a security layer, a continuous compliance checker, and the foundation of a truly codified infrastructure where code is the source of truth rather than fiction.

Native AWS tools for detecting drift

AWS provides several native services to identify and remediate drift. AWS CloudFormation, the reference tool for IaC on AWS, offers Drift Detection as a built-in feature. Triggered through the API or the console, it analyzes the declared state of the stack and compares it against the resources actually provisioned. CloudFormation reports in detail which resources have changed, which parameters no longer match, and even attempts to classify the severity of the drift (deletion, structural change, non-critical parameter change). This scan is point-in-time but free and precise for anything deployed through CloudFormation itself. AWS Config rounds out the picture by offering continuous monitoring. Configured to track changes across AWS resources (EC2, RDS, S3, IAM, VPC, and so on), Config records every modification, who made it, and when, building a complete history. You can then define rules (for example, "every S3 bucket must have encryption enabled") and Config watches continuously. When a resource becomes non-compliant (an engineer disables encryption by hand), an alert is raised. The service also generates compliance reports for audits. AWS Systems Manager Session Manager and AWS Systems Manager Documents offer another angle: automating remediations declared in AWS Systems Manager documents once drift is detected. Finally, for teams using Terraform instead of CloudFormation, Terraform Cloud and Terraform Enterprise include similar drift detection (terraform plan always compares the declared state against the real one). The strength of these tools lies in their native integration with the AWS ecosystem: minimal configuration, immediate access to AWS metadata, and traceability that aligns with CloudTrail for auditing.

Detecting drift beyond declared resources

Native AWS tools do an excellent job of covering resources provisioned by their own service (CloudFormation covers its stack, AWS Config covers any AWS resource). A complete infrastructure, however, often spills beyond that perimeter. If you run Kubernetes on AWS (EKS), drift in your Kubernetes manifests will not be caught by CloudFormation Drift Detection. If you have application code configured through third-party tools such as Helm, Ansible, or even Bash scripts, the native AWS services do not see them. This is where a broader approach comes in: using full-infrastructure scanning tools that recognize several IaC languages (Terraform, CloudFormation, Ansible, Helm, and so on) and run regular scans of your infrastructure. Open source tools such as Checkov or Trivy scan IaC code to verify compliance with best practices before deployment (a preventive check). For continuous detection in production, platforms such as Snyk Infrastructure or Wiz add a post-deployment monitoring layer, alerting on drift detected between what is in production and what is declared, regardless of the IaC tool used. These commercial solutions generally integrate AWS Config behind the scenes to provide a unified view. The advantage is broad coverage and visibility that is independent of the IaC toolchain. The drawback is the added configuration complexity and potentially subscription costs. For many scale-up teams, starting with CloudFormation Drift Detection and AWS Config is enough to cover 80% of the need, then adding layers as the scope of the infrastructure widens (multi-cloud, third-party application stacks, Kubernetes at scale).

Setting up an automated remediation loop

Detecting drift is only half the job if you do not remediate it. A mature infrastructure therefore includes an automated remediation loop. The classic pattern works in three steps. First, detection is triggered on a regular basis (through a scheduled CloudFormation scan, through AWS Config rules, or through a daily CI/CD pipeline launched for instance via GitHub Actions or AWS CodePipeline that runs a terraform plan). Next, when drift is detected, an alert is raised. This alert can be passive (sent to a team that reviews it manually via SNS or a Slack notification) or proactive (a system automatically decides whether the drift can be corrected safely). For "safe" drifts, you can configure automatic remediation. For example, if AWS Config detects that a security group rule allows unrestricted traffic (0.0.0.0/0), a predefined corrective action automatically tightens the rule according to a defined policy. CloudFormation has the same capability via SNS topics or Lambda triggers. Terraform, for its part, only remediates by re-running terraform apply against the up-to-date code. The third step, often neglected, is traceability: recording WHO corrected the drift, HOW, and AT WHAT TIME, in an audit log. This is crucial for regulatory compliance (SOC2, ISO27001) and for understanding after the fact why a remediation took place. AWS CloudTrail already captures corrections made through the AWS API. You need to make sure that automated remediations also flow through CloudTrail (and not through direct scripts running with root privileges). In practice, a mature DevOps team combines continuous detection (Config rules or a daily terraform plan) with semi-automatic remediation (fast-exposure alerts, automatic fixes for benign issues, manual review for structural changes) and traceability through CloudTrail and centralized logs. This balance maintains compliance without paralyzing development agility.

Integrating drift detection into the development and deployment cycle

For drift detection to become genuinely operational, it must fit into teams' daily work rather than remaining an isolated process for the annual audit. The best approach is to weave it into the deployment pipeline (CI/CD). When an infrastructure change is pushed as code (a commit in the Terraform or CloudFormation repository), the pipeline can run a pre-existing drift scan before applying the change. This is a state check: "OK, there is a known drift in the prod environment, and the change was already approved." It avoids deploying a change that would go out without the context of the current drift. After deployment, a post-deployment scan verifies that the infrastructure genuinely matches the freshly deployed code. If this scan detects unexpected drift (for example, a resource was deleted during the deployment for no known reason), you can trigger a rollback. For teams working across multiple environments (dev, staging, prod), it is also useful to compare drift between environments: if dev and staging are compliant but prod has drift, that signals prod deviated after the code was approved. The best results come when the IT or DevOps team defines a clear policy: "Critical drifts (security, compliance) must be corrected in under 24h. Minor drifts (non-critical parameters) must be corrected during the next infra deployment. Every remediation is traced and approved." You then automate the enforcement of that policy through tools such as AWS Config remediation actions, Terraform Cloud webhooks, or Slack alerts with built-in manual approval. The end result: an infrastructure where code and reality stay synchronized, where compliance surprises disappear, and where teams reclaim the time they used to spend fixing inconsistencies.

Common challenges and practical solutions

In practice, implementing effective drift detection runs into a few recurring pitfalls. The first is the false positive: the tool detects drift that is not really drift. For example, if a cloud resource has a parameter whose value AWS fills in by default after creation (such as an implicit egress rule on a security group), CloudFormation Drift Detection will see it as a divergence even though it is expected. The solution is to configure the IaC code carefully so it explicitly declares these expected default values, or to exclude these known noisy resources from drift scans. The second pitfall is legitimate changes that do not go through code. An operator needs to add a temporary disk to an EC2 instance for an urgent test. Or an application team creates an S3 bucket through an install script that no infra team ever approved. These changes are legitimate in the short term, but they become drift if you forget to update them in the code. The solution is clear governance: every long-lived resource MUST be declared in code before deployment. Temporary resources (dev, test, spikes) can be excluded from drift scans or tracked in a separate registry. The third challenge is scale: as the infrastructure grows (thousands of resources), scanning the entire estate every day becomes costly and generates a lot of noise. The solution is to prioritize. Scan critical resources (security, network, data) continuously. Scan the rest at a reduced frequency (weekly). Use drift reports focused on changes detected since the last scan (the delta), not the complete state. The fourth challenge is human: a team whose infra code was poor to begin with (spaghetti IaC, no modularity) will find drift detection frustrating, because it forces them to clean up their architectural mistakes rather than move forward. Here the solution is not technical: it is to rework the IaC code in parallel with rolling out drift detection, or to stage the activation of scans so as not to paralyze the workflow. In short, calibrating drift detection properly for your own infrastructure takes iteration: start simple (CloudFormation Drift Detection on critical resources), measure the rate of false positives and true positives, then refine the rules and the frequency.

AWS TEARDOWN Β· FREE

Get the AWS Teardown: where your bill really goes.

The guide listing the 12 cost areas that leak the most at scale-ups, and how to plug them. Free, by email, no strings attached.