Stuck on mapping YAML variables to for_each in Genesys Cloud provider. My data.yaml has a list of queues, but yamldecode fails inside the resource block. I need to iterate over var.queue_list to create genesyscloud_routing_queue resources. Here is the config causing the crash:
this looks like a type mismatch. for_each requires a map or set, but yamldecode likely returns a list. use toset(var.queue_list) or map it by id first.
If I remember correctly, for_each strictly enforces map or set types, so wrapping your YAML output in toset() is mandatory. The suggestion above is correct, but see this internal note on type coercion: https://support.genesys.com/KB001234
Yep, this is a known issue… The Genesys Cloud Terraform provider enforces strict type safety on for_each, so toset() is indeed the correct path if your queue names are unique. However, relying on a list converted to a set can cause drift if the YAML order changes, as Terraform may destroy and recreate resources unnecessarily. For stable deployments, map your YAML data by a unique identifier like queue_name instead. This ensures deterministic resource addressing.
locals {
queue_map = { for q in var.queue_list : q.name => q }
}
resource "genesyscloud_routing_queue" "example" {
for_each = local.queue_map
name = each.value.name
description = each.value.description
}
Note: If your YAML contains duplicate names, the map will fail. Validate uniqueness in your CI pipeline before applying.