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 editon a live deployment.
Why it's a problem:
- The next
terraform applyor 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 planon 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:
- All changes through code and pipelines — no manual changes in production.
- Restrict console/SSH write access in production; read-only by default, break-glass access for emergencies.
- Self-healing — Argo CD auto-sync with self-heal reverts manual cluster edits.
- Immutable infrastructure — replace servers instead of changing them.
- 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).
More on Infrastructure & cloud basics
What is the difference between declarative and imperative infrastructure?BeginnerWhat is idempotency, and why is it important in automation?BeginnerWhat is immutable infrastructure?BeginnerWhat does "pets vs cattle" mean?BeginnerWhat is cloud computing, and what are IaaS, PaaS and SaaS?BeginnerWhat is the shared responsibility model in the cloud?Beginner