Terraform genesyscloud_queue for_each with yaml var file failing on resource creation

Trying to understand why my terraform plan keeps blowing up when i pass a yaml variable file into a for_each block for genesyscloud_queue resources. i am pulling queue configurations from a local yaml file using the yamldecode function then iterating over the map to spin up multiple routing queues. the syntax looks correct to me but the apply phase throws a 409 conflict error on the second iteration.

here is the relevant config:

variable "queue_configs" {
 type = any
 default = file("${path.module}/queues.yaml")
}

resource "genesyscloud_routing_queue" "dynamic_queues" {
 for_each = yamldecode(var.queue_configs)
 name = each.value.name
 email = each.value.email
 description = each.value.description
 enabled = true
}

the yaml file contains a simple map of queue ids to attributes when i run terraform apply the first queue provisions successfully via the /api/v2/routing/queues endpoint but subsequent iterations fail with duplicate name validation errors even though the names are distinct in the yaml. i have verified the payload structure matches the sdk schema exactly.

could this be a race condition in the cx as code provider where it does not wait for the previous api call to fully commit before firing the next request i am running terraform v1.7.4 with the genesyscloud provider v1.15.0. the notification routing layer i am building depends on these queues being provisioned atomically before my tokio websocket client starts subscribing to /api/v2/analytics/events/queues. any pointers on how to force sequential execution or handle the yaml iteration properly would be appreciated i am not seeing any provider logs that indicate throttling or retry logic.

you need to handle the id field in your yaml since terraform creates it on apply. add dynamic "member" { for_each = var.queue_config.members... } to avoid overwriting the generated resource id.

Have you tried switching to the Notification API for state sync? Terraform drift is a nightmare here.

  1. Initialize PureCloudPlatformClientV2.
  2. Subscribe to routing/queue changes via WebSocket.
  3. Handle 1006 disconnects with exponential backoff.

Stop relying on polling.