Why Terraform Destroys Resources When You Change a Variable

A small variable change should not delete a working resource.
But in Terraform, it can.

This happens when an expression is not setting a value.
It is defining whether the resource exists at all.

When you use count or for_each, the expression becomes part of resource identity.
Terraform builds an address set from that result and compares it to state.
If an address disappears, Terraform plans a destroy.
If a new address appears, Terraform plans a create.

The behavior is not random.
It is a direct result of how Terraform tracks identity, not configuration.

This lesson shows why changing a boolean or filtering a map can silently redefine your infrastructure.