Course contentsShow
← Cloud and Infrastructure
Lesson 719 of 2,98913. Infrastructure as Code FoundationsFree lesson

Handling Drift and Manual Changes

Learn strategies for detecting and resolving configuration drift when manual changes occur outside IaC.

Handling Drift and Manual Changes

What you'll learn: How to detect when your actual infrastructure no longer matches your IaC definitions and what to do about it.

What Is Drift?

Drift occurs when someone (or something) modifies your infrastructure directly—outside of your Infrastructure as Code workflow. Imagine you've written a recipe (your IaC code) for baking a cake, but while you weren't looking, someone added extra frosting or changed the oven temperature. Your recipe no longer matches the actual cake!

Common drift scenarios include:

  • A teammate manually changes a server setting through the cloud console
  • An automated scaling policy modifies resource configurations
  • A security patch updates firewall rules directly
  • Someone deletes a resource without updating the code

Detecting Drift

Your state file (introduced earlier) is your source of truth. Drift detection compares:

  1. What your state file says should exist
  2. What actually exists in your cloud provider

Most IaC tools offer a "plan" or "preview" command that highlights differences without making changes. Run this regularly to catch drift early.

Resolving Drift

You have two main strategies:

1. Import the changes back into code — Update your IaC files to match the manual change, then reconcile your state file. Use this when the manual change was intentional and beneficial.

2. Revert to the code — Re-apply your IaC to override the manual change and restore your defined configuration. Use this when the drift was accidental or unauthorized.

Prevention

  • Restrict direct access to production resources
  • Use read-only cloud console access where possible
  • Schedule regular drift detection scans
  • Document all emergency manual changes immediately

Key Takeaway: Drift is inevitable in real environments; detecting it quickly through state comparison and having a clear process to either adopt or revert changes keeps your infrastructure reliable and your code trustworthy.