Terraform for_each with YAML for queues failing on attribute lookup

Getting a Reference to undeclared resource error when trying to map queue names from a YAML file using for_each. I’ve loaded the file with yamldecode but terraform plan can’t find the attributes in the loop. Here’s the snippet:

locals {
 queues = yamldecode(file("queues.yaml"))
}

resource "genesyscloud_routing_queue" "test" {
 for_each = local.queues
 name = each.value.name
}

The YAML structure is just a list of objects. It works fine with a simple map, but this nested list format breaks the attribute reference.

The yamldecode function returns a complex object, not a map. Terraform’s for_each requires a map or set. You’ll need to convert the list to a map using a for expression.

locals {
 queues_map = { for q in yamldecode(file("queues.yaml")).queues : q.name => q }
}

resource "genesyscloud_routing_queue" "test" {
 for_each = local.queues_map
 name = each.key
}