title: Terraform for_each + tuple as multi-dimensional array
body: <p>I have a locals file to describe different parameters, for different environments e.g.</p>
  <p><code>parameters.tf</code>:</p>
  <pre><code>locals {
    env = {
      dev1 = {
       ...
        natgw_route_table_id           = &quot;rtb-048.....&quot;
        transit_gateway_route_table_id = &quot;tgw-rtb-05cc...&quot;
        transit_gateway_id             = &quot;tgw-087...&quot;
        ec2_route_table_id             = &quot;rtb-059...&quot;
        ec2routes_ngw = {
          f1 = {
            destination_cidr = &quot;10.12.13.14/24&quot;\
            nat_gateway_id                = &quot;nat-02a...&quot; 
            transit_gateway_attachment_id = &quot;tgw-attach-0f07...&quot;
          }
          f2 = {
            destination_cidr = &quot;10.12.13.15/32&quot;
            nat_gateway_id   = &quot;nat-0a6c...&quot; 
            transit_gateway_attachment_id = &quot;tgw-attach-028&quot;
          }
       
        }
      }
      ...
      prod = {
         natgw_route_table_id           = &quot;rtb-0be...&quot;
        transit_gateway_route_table_id = &quot;tgw-rtb-0ab7...&quot;
        transit_gateway_id             = &quot;tgw-00dfa...&quot;
        ec2_route_table_id             = [&quot;rtb-0de4...&quot;, &quot;rtb-070a9...&quot;, &quot;rtb-044a...&quot;, &quot;rtb-0c8a...&quot;]
        ec2routes_ngw = {
          f1 = {
              destination_cidr = &quot;10.10.11.12/24&quot;
              nat_gateway_id                = [&quot;nat-09af...&quot;, &quot;nat-042b...&quot;, &quot;nat-078e...&quot;, &quot;nat-0cd2c...&quot;] 
              transit_gateway_attachment_id = &quot;tgw-attach-0ed5025f6fc1731f7&quot;
          }
        }
     }
    }
  }
  
  </code></pre>
  <p>As you can see, for an environment called dev1 we have a single subnet to a single nat gateway.
  This is easily solved with a resource like:</p>
  <pre><code>resource &quot;aws_route&quot; &quot;natgw&quot; {
    for_each               = { for k, v in local.workspace[&quot;ec2routes_ngw&quot;] : k =&gt; v if(local.workspace[&quot;releaseStage&quot;] != &quot;prod&quot;)}
    route_table_id         = local.workspace[&quot;ec2_route_table_id&quot;]
    destination_cidr_block = each.value.destination_cidr
    nat_gateway_id         = each.value.nat_gateway_id
  }
  </code></pre>
  <p>However, for <code>prod</code> and potentially others we have a route table for each AZ Subnet with its respective NAT Gateway.</p>
  <p>Now, I could hack this to work but I would prefer to do this a little more elegantly.</p>
  <p>I found some similar examples using <code>for_each</code> with a flattened locals file. I don't mind having a separate resource for those <code>prod</code> type environments but would prefer to not hardcode it.</p>
  <p>Any ideas are appreciated.</p>