Terraform throws an Inappropriate value for attribute "for_each": element "name" is tuple error during the plan phase. The config uses locals { queue_data = yamldecode(file("${path.module}/queues.yaml")) } with resource "genesyscloud_routing_queue" "main" { for_each = local.queue_data }. Trying to spin up a batch of routing queues using for_each and a local YAML var file, but the CXone provider keeps choking on the map conversion. The YAML is just a flat list of objects and it’s throwing a type mismatch, but the plan fails anyway.
Have you tried wrapping that yamldecode output in toset? The error message is pretty specific about the element being a tuple, which usually means Terraform sees the YAML keys as a list of pairs instead of a flat map. for_each expects a set of strings or a map.
Try this adjustment in your locals block:
locals {
queue_map = { for k, v in yamldecode(file("${path.module}/queues.yaml")) : k => v }
queue_set = toset(keys(local.queue_map))
}
Then use for_each = local.queue_set on the resource. It forces the keys into a proper set. If your YAML has nested structures, you might need to flatten it first, but usually, just extracting the keys works.
I ran into this last week when importing a batch of queues. The provider doesn’t like the raw tuple structure from yamldecode. Also, make sure the YAML keys don’t have spaces or special characters that Terraform chokes on for resource IDs. It’s a bit finicky with naming conventions.
toset won’t fix this if the YAML structure is actually a list of mappings. You need to convert it to a map keyed by a unique identifier first. Try this pattern: { for q in local.queue_data : q.name => q }.