Prompt
Why does Terraform keep detecting drift on unchanged resources?
Latest observation
Terraform can report drift on resources even when you haven’t intentionally changed anything for a few common reasons:
1) The provider reads values that are computed or normalized
Some resource attributes are set by the provider or API after creation, not by your config. Examples:
- timestamps
- IDs
- defaulted fields
- ordering of lists/sets
- API-normalized values like case changes, whitespace, or JSON formatting
Terraform sees the refreshed state and thinks it differs from config.
2) The remote system changes things automatically
Cloud services often mutate resources behind the scenes:
- security group rules reordered
- tags added by the platform
- passwords/keys rotated
- defaults injected by the API
- managed services adjusting settings
Terraform refreshes from the API and detects those differences.
3) The provider has inconsistent diff handling
Sometimes the provider itself has bugs or imperfect schemas:
- incorrect
Computed/Optionalflags - unstable field ordering
- force-new attributes changing unexpectedly
- fields that are semantically equal but textually different
This is a common cause of “phantom drift.”
4) Your config and the remote object aren’t actually identical
Even small differences matter:
nullvs empty string- list vs set ordering
- omitted argument vs explicit default
- numeric/string type coercion
- case sensitivity
5) Data source or dynamic input changes
If your config uses:
timestamp()random_*resources without stable keepersfilesha*on changing files- external data sources
- values from CI/CD environment variables
then the plan can change even though the managed resource itself didn’t.
6) State is stale or was modified externally
If state wasn’t refreshed correctly, or someone changed the resource outside Terraform, drift can appear. Less commonly:
- backend/state locking issues
- partial applies
- manual state edits
- importing with slightly different settings
How to diagnose
-
Run:
terraform planLook closely at which attribute is changing.
-
Refresh state only:
terraform plan -refresh-onlyThis shows what Terraform thinks changed in the real world.
-
Compare config, state, and remote API output if possible.
-
Check provider docs/issues for known drift bugs.
-
If the change is expected and harmless, consider:
lifecycle { ignore_changes = [...] }- setting the attribute explicitly
- upgrading the provider
Best fix depends on the cause
- API normalization/order changes → use stable types, explicit ordering, or
ignore_changes - Automatic platform changes → configure the service to stop mutating if possible
- Provider bug → upgrade or pin a different provider version
- Dynamic inputs → remove non-deterministic functions from resource arguments
If you want, I can help interpret a specific Terraform plan diff and tell you why that exact drift is happening.
Brands