Terraform for_each with YAML vars for Genesys queues

Trying to spin up queues from a YAML var file using for_each. The map keys are fine, but the routing_queue resource keeps complaining about dynamic block syntax when I try to map the skills from the YAML structure. Is there a clean way to flatten that nested list for the skills block? Here’s the rough config I’m working with. It’s throwing a parse error on the assignment line.

The issue isn’t really the for_each loop itself. Terraform handles maps well enough. The trouble starts when you try to shove a nested YAML list directly into the skills block without converting it to the specific object structure the provider expects. The routing_queue resource doesn’t take a flat list of strings for skills. It needs a list of objects with a id field.

You’re probably trying to assign value.skills directly, which is just a list of strings from your YAML. You need to transform that list into a list of maps.

Here’s how I handle it in my custom desktop setup scripts. First, ensure your YAML looks like this:

queues:
 support_us:
 name: "US Support"
 skills: ["english", "tier1"]

Then, in your Terraform module, you need a locals block to do the heavy lifting. Don’t try to do this inline in the resource definition. It gets messy fast.

locals {
 # Flatten the nested structure into a format the provider understands
 queue_configs = {
 for key, val in var.queues : key => {
 name = val.name
 skills = [
 for skill in val.skills : {
 id = skill
 }
 ]
 }
 }
}

resource "genesyscloud_routing_queue" "queue" {
 for_each = local.queue_configs

 name = each.value.name

 # This is the critical part. The provider expects a list of objects.
 skills = each.value.skills
}

The key is that for loop inside the locals block. It iterates over the strings in val.skills and wraps each one in a map { id = skill }. This matches the API schema exactly. If you skip this step, the provider throws a type mismatch error because it’s expecting an object but getting a string.

Also, make sure you’re using the latest version of the Genesys Cloud provider. Older versions had quirks with how they parsed dynamic blocks, but the current stable release handles this list-of-objects pattern cleanly. If you’re still seeing parse errors, check your HCL syntax for missing commas or braces. It’s usually a simple typo.

One more thing. If your skills list is empty, the skills block might cause issues depending on the provider version. You might want to add a conditional to only include the block if the list isn’t empty. But for most cases, the transformation above should clear up the parse error you’re hitting.