A for_each key isn't a label. It's half of the resource address, terraform_data.queue["prod-orders"], and the state tracks the object under that address. Change the key and the plan doesn't see a rename. It sees one object to destroy and another to create.
So I get nervous when the keys come out of an expression.
locals {
queues = { for q in var.queues : "${q.env}-${q.name}" => q }
}
resource "terraform_data" "queue" {
for_each = local.queues
input = each.value
}
Looks harmless. Then someone decides the key reads better as name first, edits one line in locals, and the review diff is one line long. The plan is where the replacement of every instance shows up, and the plan is the part people skim. My preference is keys written out in the file, or taken straight from one field that never changes, with any clever reshaping kept in the values.
