Terraform for_each with YAML queue definitions failing on attribute lookup

Why does the genesyscloud_routing_queue resource throws an attribute lookup error when using for_each with a YAML-sourced variable file?

I am trying to generate multiple queues from a single YAML definition file to keep our CX as Code config DRY. The variable file queues.yaml contains a list of objects with name, description, and outbound_capacity.

Here is the TF block:

variable "queues" {
 type = any
}

resource "genesyscloud_routing_queue" "dynamic_queues" {
 for_each = var.queues
 name = each.value.name
 description = each.value.description
 outbound_capacity = each.value.outbound_capacity
}

When I run terraform plan, it fails with:
Error: Unsupported attribute. This object does not have an attribute named "name".

I have verified the YAML structure is valid JSON-compatible objects. I am passing the file using -var-file=queues.yaml. The error suggests var.queues is being treated as a list or a single object rather than a map, but for_each expects a map or set of strings.

How do I correctly map a list of YAML objects into a structure that for_each accepts for the queue resource? I am in Paris, so if this is a timezone-sensitive parsing issue, I am awake to debug it.

Thanks everyone.

Ah, this is a recognized issue with type coercion in the Terraform provider when handling YAML lists via for_each.

The provider expects a map of objects, not a list. You must convert your YAML list into a map using tomap and a unique key (like name) before passing it to for_each. Here is the corrected variable definition and resource block:

variable "queues_map" {
 type = map(object({
 name = string
 description = string
 outbound_capacity = number
 }))
 default = {} # Populate via terraform.tfvars or YAML import
}

resource "genesyscloud_routing_queue" "example" {
 for_each = var.queues_map

 name = each.value.name
 description = each.value.description
 outbound_capacity = each.value.outbound_capacity
}

Ensure your YAML input is transformed into this map structure before applying, otherwise the attribute lookup on each.value will fail.