Interview Prep/DevOps Fundamentals/Infrastructure & cloud basics

What is configuration drift, and how do you prevent it?

BeginnerConceptInfrastructure & cloud basics
Answer

In one line: Configuration drift is when real servers or cloud resources slowly become different from what's defined in code — usually because someone changed something by hand — and it causes surprises, failed deployments and security gaps.

How drift happens:

  • Someone logs into the console and opens a security group port "just for testing".
  • An engineer fixes a production issue directly on a server with SSH and never updates the code.
  • An auto-update changes a package version on some servers but not others.
  • kubectl edit on a live deployment.

Why it's a problem:

  • The next terraform apply or deployment may undo the manual fix, or fail unexpectedly.
  • Environments stop matching — "works in staging, fails in prod".
  • Security holes stay open without anyone knowing.
  • Disaster recovery from code no longer rebuilds what you actually had.

How to detect drift:

  • terraform plan on a schedule (for example nightly) — any planned change means drift. Tools like Terraform Cloud, Spacelift and driftctl-style checks automate this.
  • Argo CD / Flux show Kubernetes apps as OutOfSync when the cluster differs from Git.
  • AWS Config / Azure Policy detect resources that break rules.
  • Ansible in check mode (--check --diff).

How to prevent drift:

  1. All changes through code and pipelines — no manual changes in production.
  2. Restrict console/SSH write access in production; read-only by default, break-glass access for emergencies.
  3. Self-healing — Argo CD auto-sync with self-heal reverts manual cluster edits.
  4. Immutable infrastructure — replace servers instead of changing them.
  5. If an emergency manual fix happens, put it into code immediately afterwards.

Example: a nightly pipeline runs terraform plan -detailed-exitcode on production; exit code 2 (changes present) posts an alert to Slack with the diff.

Tip for interviews: cover both detection (scheduled plans, GitOps) and prevention (pipeline-only changes, restricted access).

All DevOps Fundamentals questions

More on Infrastructure & cloud basics