Terraform for_each with YAML variables for Genesys queues breaking on special characters

Trying to automate queue creation for our Berlin site using Terraform and the Genesys Cloud provider. We have a YAML file defining about 30 queues with their names, wrap-up codes, and skill assignments. The goal is to use for_each to iterate over the map loaded from the YAML file and create each queue resource.

The YAML structure looks like this:

queues:
 sales_tier1:
 name: "Sales Tier 1"
 description: "First line sales"
 support_de:
 name: "Support DE"
 description: "German support"

In the Terraform module, I’m loading this with yamldecode and passing it to the gen_cloud_routing_queue resource:

locals {
 queue_data = yamldecode(file("${path.module}/queues.yaml")).queues
}

resource "gen_cloud_routing_queue" "queues" {
 for_each = local.queue_data
 name = each.value.name
 description = each.value.description
 # ... other attributes
}

The problem is that when I run terraform plan, it fails if any queue name contains special characters like apostrophes or hyphens. For example, a name like “Sales-Tier 1” or “O’Brien Support” causes a parsing error or an invalid resource name error in the state file. Terraform seems to be trying to use the YAML key as the resource identifier, which is fine, but the actual API call fails because the queue name validation is stricter than I expected, or maybe the for_each map key is clashing with the API’s ID generation.

I’ve tried escaping the names in the YAML, but that doesn’t help. The error message says Error: Invalid resource name. Is there a way to force Terraform to use a clean key for for_each while still passing the raw, special-character-filled name to the API? Or is the Genesys provider just choking on the input? We need to keep the exact naming convention for the agents. Here is the error output:

Error: Invalid resource name
 on main.tf line 12:
 resource "gen_cloud_routing_queue" "queues" {

Any ideas on how to handle this?