Published on

Detecting drift

Drift is the distance between what the code says and what actually exists. It always appears; what distinguishes a healthy infrastructure is that it detects it early and decides what to do with each difference.

Service line Automation and IaC

Drift always arrives

However much discipline there is, reality moves away from the code: an emergency change made by hand, an automatic adjustment by the provider, an update that modified a setting. That distance is called drift.

Its existing is not a failure. Not knowing about it is. Undetected drift is what causes an innocent code change to 'undo' an emergency fix nobody carried over, or a rebuilt-from-code environment not to behave like the original.

Checking on a schedule

Differences between code and realityThe number of differences over twelve weeks: with a daily check it stays low; every difference requires a decision.IAC · DRIFTDifferences between code and reality05101520w1w2w3w4w5w6w7w8w9w10w11w12daily checkcheck every two weekscheck and correctionEVERY DIFFERENCE, A DECISIONReality was righttaken into the codeThe code is rightapplied againLeaving it aloneis not an optionIllustrative data; they do not correspond to any real caseN100F · n100f.com

Detection is done periodically and automatically:

  • For the infrastructure: the plan is calculated against the environment without applying it. If the plan is not empty, there is drift.
  • For the servers: each one is checked against its baseline, as we saw in the previous article.

The more frequent the check, the smaller the differences and the easier it is to know where they came from.

Every difference, a decision

Detecting is not enough: every difference requires choosing between two paths.

  1. Reality was right. The change by hand was necessary (an emergency adjustment, for instance). It is taken into the code, reviewed and applied formally.
  2. The code is right. The change by hand should not have existed. The code is applied again to return reality to what is declared.

What will not do is the third option, the most common one: leaving it alone. Every ignored drift makes the next one harder to understand.

Reducing the source

The best way to have little drift is to leave little room for creating it: write permissions in the console for emergencies only, with a record of who used them, and the rule that every emergency change is carried into the code that same day.

With reality and the code aligned, you can face what frightens people most: changing important things in production.


How we apply it: Automation and IaC.

If your cloud cost keeps growing and nobody knows why, or your architecture depends on whoever built it, let’s talk.

Let’s talk