how/state
Someone changed a tag in the AWS Console, and Terraform suddenly shows changes. What drift is, why it happens, and three ways to live with it.
Drift is when the real state of a resource in the cloud diverges from what Terraform holds in its state.
It happens for several reasons:
Press ▶ to follow the life cycle of a single drift: how it appeared, how Terraform saw it, and three ways to resolve it.
Right after a successful terraform apply, all three sources of truth
match: the HCL describes a bucket with the tag Owner = "student", the state knows
about this tag, and AWS has exactly that bucket.
This is the base state of Terraform. Any repeat plan is clean.
recap
Three strategies for dealing with drift:
terraform apply brings the cloud back to the HCL.
Use this when the HCL is the truth and the cloud is wrong.main.tf so it reflects the new truth, then run
apply (or refresh plus a manual edit of the state block).Which strategy and when:
A regular drift check in CI (see tf-drift-detection) is mandatory in production. Drift that no one sees turns into an incident.