Terraform for_each with YAML variable file for Genesys Cloud queues

We’re trying to automate the creation of multiple Genesys Cloud queues using the genesyscloud_queue resource. Instead of hardcoding each queue in the Terraform file, we want to read from a YAML variable file and use for_each to loop through the entries.

Here’s the structure of our queues.yaml file:

queues:
 - name: "Support Queue"
 description: "General support"
 wrap_up_code: "DEFAULT"
 - name: "Sales Queue"
 description: "Sales inquiries"
 wrap_up_code: "SALES"

In our Terraform code, we’re using the yamldecode function to load the file:

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

resource "genesyscloud_queue" "queues" {
 for_each = toset(local.queues_config)
 name = each.value.name
 description = each.value.description
 wrap_up_code = each.value.wrap_up_code
}

The issue is that for_each expects a map or a set of strings, but we’re passing a list of objects. Terraform throws an error: “Invalid for_each argument”.

I’ve tried converting the list to a map using toset and zipmap, but I’m struggling to create a unique key for each queue. The name field is unique, but I’m not sure how to use it as the key while still accessing the other attributes.

Has anyone successfully used for_each with a YAML file for Genesys Cloud resources? What’s the best way to structure the YAML and the Terraform code to avoid this error? We’re using Terraform v1.5.0 and the Genesys Cloud provider v1.1.0. Any help would be appreciated.