Terraform for_each with YAML data source creates duplicate queues on refresh

Running into a weird state drift issue when using for_each to provision queues from a YAML config file. The initial terraform apply works fine, creating three queues. But on the second run, or after a minor edit to the YAML, Terraform wants to destroy the existing queues and create new ones, even though the IDs haven’t changed.

Here’s the setup:

data "external" "queues" {
 program = ["python", "scripts/parse_yaml.py"]
}

resource "genesyscloud_routing_queue" "queue" {
 for_each = jsondecode(data.external.queues.result)["queues"]
 name = each.value.name
 // ... other attrs
}

The parse_yaml.py script outputs JSON. I’ve verified the output is stable. The issue seems to be that the for_each keys are not persisting correctly in the state file, or perhaps the external data source is re-evaluating and producing slightly different keys due to floating point or string encoding quirks in the YAML parsing.

The error is just the plan diff:

# module.routing.genesyscloud_routing_queue.queue["sales-us"] will be destroyed
# (because each key "sales-us" has changed to "sales-us"])
- resource "genesyscloud_routing_queue" "queue" {
 - id = "12345" -> null
 - name = "Sales US" -> null
 }

# module.routing.genesyscloud_routing_queue.queue["sales-us"] will be created
+ resource "genesyscloud_routing_queue" "queue" {
 + name = "Sales US"
 }

Notice the key change from sales-us to sales-us]. That trailing bracket shouldn’t be there. Is this a bug in the external data source handling or am I missing a depends_on?