1.Desired State and Actual State
Infrastructure as code describes a desired state: what should exist and how it should be configured. The account holds the actual state: what does exist right now. Drift is the difference between them, and it appears the moment anyone changes a resource outside the tool that created it.
Key features
- A resource has drifted if any of its actual property values differ from the expected values, including a property or resource being deleted
- A stack has drifted if one or more of its resources have drifted
- CloudFormation compares expected values — from the template and its parameters — with the actual values as they currently exist
- Only explicitly set property values are compared: defaults that were never written in the template are not tracked, so set a property even when setting it to its default
- CloudFormation also detects drift on stack-level tags
- Detecting drift on a stack does not detect drift on its nested stacks; those need their own detection operation
Where drift comes from, and how visible it is
- A diagram with two boxes side by side and a labelled gap between them.
- On the left, desired state: the template in version control, describing what should exist, reviewed and reproducible.
- On the right, actual state: the resources in the account, changed by deploys, by consoles, by scripts, and by services acting on your behalf.
- Between them a gap labelled drift, with the note that it appears whenever a change is made outside the tool.
- Below, four routes to closing the gap: update the template to match reality, redeploy the template over reality, import an unmanaged resource into the stack, or accept and record the difference as a documented exception.
Signature
desired state (template) ≠ actual state (account) ⇒ drift · resolve by updating, redeploying, importing, or recording
The template is a claim; the account is the fact; drift is the gap, and it is the default outcome rather than an anomaly. Only explicitly set properties are compared, so set them even at their defaults, and resolve every drift by deciding which side was right and writing that decision back into the template.