Terraform Genesys Cloud Provider: Dynamic Queue Creation with for_each and YAML Variables

Is it possible to dynamically generate multiple genesyscloud_routing_queue resources using for_each while parsing a YAML variable file for the configuration data?

I am building a Node.js-based deployment pipeline that generates Terraform state files from a centralized YAML config. The goal is to declaratively manage queue structures without hardcoding resource blocks. I have a queues.yaml file structured like this:

queues:
 support_us:
 name: "US Support"
 description: "Primary US queue"
 wrap_up_timeout: 45000
 sales_eu:
 name: "EU Sales"
 description: "European sales team"
 wrap_up_timeout: 30000

In my Terraform module, I am attempting to use yamldecode to load this file and iterate over the keys:

locals {
 queue_data = yamldecode(file("${path.module}/queues.yaml")).queues
}

resource "genesyscloud_routing_queue" "dynamic_queues" {
 for_each = local.queue_data

 name = each.value.name
 description = each.value.description
 wrap_up_timeout_millis = each.value.wrap_up_timeout
 
 # Other standard queue attributes...
}

However, when I run terraform plan, I encounter a validation error indicating that the for_each argument requires a map or a set of strings, but the output of yamldecode seems to be interpreted as a list of objects in some contexts, or perhaps the nested structure is causing type mismatch issues. The error message is:

Error: Invalid for_each argument

 on main.tf line 10, in resource "genesyscloud_routing_queue" "dynamic_queues":
 10: for_each = local.queue_data

The "for_each" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created.

I suspect the issue might be related to how Terraform handles dynamic data sources versus static files during the plan phase, or perhaps I need to explicitly cast the YAML map to a Terraform map type. I have tried using toset(keys(local.queue_data)) but then I lose the access to the values (each.value).

Has anyone successfully implemented a pattern for bulk queue creation from external YAML/JSON sources using the Genesys Cloud Terraform provider? I want to ensure the resource IDs are stable across deployments. Any insights on handling the data type conversion or alternative approaches for dynamic resource generation would be appreciated.

Thanks for the help.

I typically get around this by leveraging yamldecode within the for_each argument to map directly to the queue configuration.

  1. Define the resource block with for_each = yamldecode(file("queues.yaml")).
  2. Map the attributes like name and description to each.value.name and each.value.description.
  3. Ensure the YAML structure is a mapping of unique keys to objects to satisfy the for_each requirement.