Terraform for_each with YAML data source for queues throws 'Inappropriate value for attribute'

Hey everyone,

I’m trying to automate the creation of about 20 support queues using Terraform and the Genesys Cloud provider. I’ve got a variables.yaml file that lists the queue names and their associated routing strategies. I’m using the yaml data source to parse it.

The issue is when I try to use for_each on the parsed map. Terraform complains that the value isn’t a map of strings, even though I can see the keys and values in the debug output.

Here’s the data source setup:

data "yaml_file" "queue_vars" {
 filename = "vars/queues.yaml"
}

locals {
 # This returns a map of maps
 queue_config = yamldecode(file("vars/queues.yaml"))
}

And here’s the resource block that’s failing:

resource "genesyscloud_routing_queue" "support_queues" {
 for_each = local.queue_config

 name = each.value.name
 description = "Auto-generated queue for ${each.key}"
 
 routing_skills {
 skill = each.value.skill_id
 }

 routing_email_enabled = true
 routing_sms_enabled = false
}

The error I get is:

Error: Inappropriate value for attribute "for_each": element "queue_name": string required.

Wait, that doesn’t sound right. for_each expects a map or a set of strings. If I pass a map of objects (which yamldecode gives me), it should work as long as I reference each.key and each.value correctly.

I tried wrapping it in toset(keys(local.queue_config)) but then I lost access to the nested values like skill_id.

Is the yaml_file data source behaving differently than standard yamldecode? Or am I missing a step to flatten this into something the provider accepts? I’ve used for_each with maps of strings before for users, but queues have way more attributes.

Any pointers on how to structure the YAML or the locals block so the provider doesn’t freak out?