Skip to content

Lesson 6 of 9 · 22m

Drift Detection and Reconciliation

Infrastructure drift is a governance signal — detect it continuously, classify causes, and reconcile without destroying valid emergency fixes.

Terraform believes the world matches state plus the last planned changes. Reality disagrees. Someone clicks in the console during an incident, autoscaling changes desired capacity, a cloud provider mutates defaults, or a legacy process edits the same resource. Drift is not automatically evil. Undetected drift is.

Refresh-only plans expose external change

Modern Terraform can inspect drift without proposing configuration changes:

terraform plan -refresh-only

This compares real infrastructure with state and reports differences. It is a diagnostic operation. Running it in CI on a schedule for important states gives you a drift signal before the next delivery pipeline discovers it at the worst possible time.

For persistent estates, wrap that in automation with a non-zero exit behavior or reporting integration. Do not page humans for cosmetic provider noise; do page or ticket for production network, IAM, database, and public-exposure drift.

Drift has causes, and the cause determines the response

  1. Emergency manual change — preserve the intent, encode it in Terraform, and document why.
  2. Unauthorized or accidental change — revert through Terraform and tighten access.
  3. Provider behavior — model the provider-managed attribute or ignore it explicitly.
  4. Competing automation — assign ownership; two controllers managing the same fields will fight forever.

The wrong response is blind reversion. During an outage, an engineer may open a security group, increase capacity, or detach a broken target. Terraform then becomes the thing that re-breaks production if you simply apply the old configuration.

Ignore only what is genuinely external

lifecycle {
  ignore_changes = [
    desired_count,
  ]
}

ignore_changes is appropriate when another system owns a field — autoscaling desired count is the classic example. It is not appropriate as a way to make noisy plans disappear. Every ignored field is a hole in your governance model, so the configuration should say which system owns that hole.

Reconciliation is a workflow

A mature loop looks like: detect drift, snapshot evidence, classify cause, decide encode/revert/delegate, execute through Terraform where possible, and record exceptions. Repeated drift in one resource usually means the ownership boundary was drawn in the wrong place. Fix the architecture, not just the resource.

Field notes

  • Scheduled drift detection matters most for rarely-changing production stacks; frequent deploy pipelines mask drift until apply time.
  • Console audit trails such as CloudTrail are often the fastest way to classify who changed what.
  • Terraform Cloud and HCP Terraform have health or drift features, but they do not replace ownership decisions.
  • If emergency access requires console writes, require a follow-up ticket to encode or revert them.

Was this lesson helpful?

Sign in to rate