Use setproduct on list(object{}) and inject value as list(string)

I have a list of objects:

variable "custom_instance_templates" {
  type = list(object({
    name              = string
    machine_type      = string
    automatic_restart = bool
    host_maintenance  = string
    boot_disk_source  = string
    tags              = list(string)

and I have a list of strings:

variable "subnets" {
  type = list(string)

I want to essentially create a setproduct where the final output is a list containing the custom_instance_templates with an injected subnet key mapping to the list of subnets.

    name              = "temp1"
    subnet = subnet[0]
    name              = "temp1"
    subnet = subnet[1]

I have the resource iterating over the list of custom_templates * subnets

I have tried variations of:

// Expected output
// [
//   [ { template0 }, "subnet0" ],
//   [ { template1 }, "subnet0" ]
// ]
template_subnet_tuple = [
  for pair in setproduct(local.templates, var.subnets) : {
    template = pair[0]
    subnet = pair[1]

// The given key does not identify an element in this collection value.
instance_templates = [
  for tuple in local.template_subnet_tuple : {
    "${tuple[0].subnet}" = tuple[1]

The core of my problem is I dont really have a way of validating any of the variables Im building along the way, because things are waiting for a terraform apply. If I had a way of printing out what template_subnet_tuple was, or what the resulting list of a for loop, I could reason better about how to smash the data into the output I want to consume.

I’ve looked at the advanced examples on:

However, again, its hard to reason about the variables that are created:

I also see that this is close to the problem here: but far enough away from my issue that I’m running into the same issue as the advanced setproduct example.

I figured out how to get terraform console going with this example. The magic is:

  test = [
    for pair in setproduct(local.custom_instance_templates, local.subnet_names) : merge(pair[0], {subnet = pair[1]})