Terraform
Feb 26, 2026 5 min read

Detect and Fix Terraform Drift

When the real cloud no longer matches your state. Reconcile without nuking resources.

Problem

Someone changed a resource in the console. `terraform plan` now wants to revert their change — or worse, recreate the resource.

Root cause

Terraform compares your config to the recorded state, not the live cloud, then computes what needs to change. Out-of-band changes show up as drift.

Solution

Refresh state without changing infra

bash
terraform plan -refresh-only

Accept the drift into state

bash
terraform apply -refresh-only

Or fold the change into config

Update the `.tf` files to match what you want, then run a normal `plan`/`apply`.

Adopt a resource created outside Terraform

bash
terraform import aws_s3_bucket.logs my-existing-bucket

Frequently asked questions

Related fixes

Weekly digest

One DevOps fix in your inbox each week

Short, practical, no fluff. Real errors, real fixes — straight from production postmortems.