For_each loop failing with yaml queue config

Need some help troubleshooting my terraform setup. trying to spin up a bunch of Genesys cloud queues using a yaml file instead of hardcoding them. the yaml looks fine but the for_each loop keeps blowing up during apply. i’m using the genesys cloud terraform provider version 1.1.0. here is the block i’ve got so far:

variable "queue_config" {
 type = any
 default = file(".tfvars.yaml")
}

resource "genesyscloud_routing_queue" "team_queues" {
 for_each = var.queue_config.queues
 name = each.value.name
 description = each.value.desc
 acw_wrapup_timeout = 30
}

when i run terraform plan it’s throwing a type mismatch error saying it expects a map of strings but gets a list. i thought yaml would parse into a map automatically. tried wrapping it in tomap but then the provider complains about missing required attributes like flow_id. the yaml just has a simple list of queue names and descriptions. maybe i need to flatten it first? don’t know how to map the yaml structure to what the routing_queue resource actually expects. the api docs show the queue object needs a skill_group_id or something but i can’t find the exact field name in the provider docs. running this on my local machine with tf 1.5.7. any pointers on getting the for_each to actually read the yaml properly?

The problem here is that file() returns a string, not a map, so for_each gets confused trying to iterate over text. i think you need to parse that yaml first. the provider doesn’t do it automatically for variables. try using the yamldecode function on the file content. it’s a bit messy but it works.

variable "queue_config" {
 type = any
 default = yamldecode(file(".tfvars.yaml"))
}

resource "genesyscloud_routing_queue" "team_queues" {
 for_each = var.queue_config
 name = each.value.name
 # ... other config
}

make sure your yaml is actually a map of objects, not just a list. if it’s a list, you’ll need to use for to convert it to a map keyed by name or id. i’m still figuring out all the terraform quirks myself. this took me a while to debug.

The problem here is that for_each expects a map or set, not a raw string. yamldecode fixes the immediate crash.

just remember that terraform’s yaml parser is strict about quotes and indentation. one missing space breaks the whole plan.

yamldecode is fine but you’re gonna hit a wall with for_each keys if your yaml isn’t a flat map. terraform needs unique string keys, not a list of objects. structure your yaml like queue_name: { config: ... } or the loop will fail again.