I’m trying to DRY up our Genesys Cloud infrastructure code by defining multiple queues in a YAML file and using for_each to create the resources. The idea is to have a queues.yaml file that lists the queue names and descriptions, then load that into HCL to drive the genesyscloud_queue resource.
Here is the basic structure I’m using. First, the YAML file queues.yaml:
queues:
- name: "Support Tier 1"
description: "First line support"
- name: "Billing & Inquiries"
description: "Handle billing questions"
Then in the Terraform module, I load it like this:
locals {
queue_data = yamldecode(file("${path.module}/queues.yaml"))
}
resource "genesyscloud_queue" "queues" {
for_each = { for q in local.queue_data.queues : q.name => q }
name = each.value.name
description = each.value.description
}
The plan works fine for the first queue. The second one fails during apply with a 400 Bad Request from the Genesys API. The error message says Invalid character in name: &.
I’ve tried wrapping the name in quotes in the YAML, escaping the ampersand, and even using replace(each.value.name, "&", "and") in the HCL, but nothing seems to stick. The API documentation doesn’t explicitly list forbidden characters for queue names, but it seems like the Terraform provider or the API itself is choking on the &.
Is there a way to sanitize the input before it hits the provider, or do I need to switch to a count index loop and manually map the names? I’d rather not go back to hardcoding if I can help it. The error log just shows the raw YAML value being sent, so the sanitization function isn’t being called at the right time in the dependency graph apparently.