Prompt
Why is my Terraform plan showing changes every time?
Latest observation
Terraform usually shows changes every run when the real infrastructure state differs from what Terraform thinks it should be, or when Terraform can’t keep a stable view of some values. Common causes:
1) Non-deterministic values in configuration
If you use functions like:
timestamp()uuid()random_*resources without stable statefile()contents that changetemplatefile()with changing inputs
Terraform may see a new value every plan.
2) Provider is returning different values each refresh
Some providers compute or normalize fields differently on every read, causing “drift” even when nothing changed. Common examples:
- ordering of lists/maps changes
- API returns default values Terraform didn’t set
- fields are rounded or reformatted
- server-side generated attributes differ slightly
3) Drift in real infrastructure
Someone or something changed resources outside Terraform:
- manual console edits
- CI/CD or scripts
- autoscaling systems
- cloud provider defaults changing after creation
Terraform refresh detects that and plans to “fix” it.
4) Sensitive ordering issues
If you use list where the provider/API treats it as a set, Terraform may keep reordering items.
Examples:
- security group rules
- IAM policies
- tags/labels in some providers
5) Computed/defaulted attributes
Some provider attributes are:
- optional but computed
- assigned defaults by the API
- updated by the provider after creation
If your config doesn’t match the normalized value exactly, Terraform may keep planning updates.
6) Floating-point or formatting differences
Tiny differences can trigger changes:
- numbers stored as strings vs numbers
- JSON/YAML formatting changes
- whitespace or newline differences in user data, scripts, or policy documents
7) State issues
If the state is stale, corrupted, or not shared properly:
- local state used by multiple users
- backend lock issues
- state not updated after failed apply
Terraform can think it needs to change resources repeatedly.
How to diagnose
-
Run:
terraform planLook for which attributes keep changing.
-
Compare with:
terraform state show <resource>to see what Terraform currently believes.
-
Check whether the change is:
- in config
- in provider-returned values
- actual drift in cloud resources
-
If needed, inspect with:
terraform plan -out=tfplan terraform show -json tfplanto identify the exact field causing diffs.
Common fixes
- Make inputs deterministic
- Sort lists before passing them
- Use
toset()when order doesn’t matter - Avoid using
timestamp()/uuid()in resource arguments - Align config with provider defaults
- Upgrade provider versions
- Add
lifecycle { ignore_changes = [...] }only when appropriate - Re-import or refresh state if it’s out of sync
If you want, paste the relevant part of your plan output and the resource config, and I can help pinpoint the exact cause.
Brands