title: Error: Invalid Index The given key does not identify an element in this collection value Transit gateway routes
body: <p>I am trying to create routes in transit gateway route table. Below is the code block.</p>
  <pre><code>locals {
    vpc_attachments_with_routes = chunklist(flatten([
      for k, v in var.vpc_attachments : setproduct([{ key = k }], v[&quot;tgw_route&quot;]) if length(lookup(v, &quot;tgw_route&quot;, {})) &gt; 0
    ]), 2)
    }
  
  resource &quot;aws_ec2_transit_gateway_route_table&quot; &quot;route&quot; {
    count = var.create_tgw ? 1 : 0
    transit_gateway_id = aws_ec2_transit_gateway.this[0].id
  }
  
  resource &quot;aws_ec2_transit_gateway_route&quot; &quot;this&quot; {
    count = length(local.vpc_attachments_with_routes)
  
    destination_cidr_block = local.vpc_attachments_with_routes[count.index][1][&quot;destination_cidr_block&quot;]
    blackhole              = lookup(local.vpc_attachments_with_routes[count.index][1], &quot;blackhole&quot;, null)
  
    transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.route[count.index].id
    transit_gateway_attachment_id  = tobool(lookup(local.vpc_attachments_with_routes[count.index][1], &quot;blackhole&quot;, false)) == false ? aws_ec2_transit_gateway_vpc_attachment.this[local.vpc_attachments_with_routes[count.index][0][&quot;key&quot;]].id : null
     depends_on = [
      aws_ec2_transit_gateway_route_table.route,
    ]
  }
  </code></pre>
  <p>Error:</p>
  <p>Error: Invalid index\n\n  on ../modules/tgw/main.tf line 85, in resource &quot;aws_ec2_transit_gateway_route&quot; &quot;this&quot;:\n  85:   transit_gateway_route_table_id = aws_ec2_transit_gateway_route_table.route[count.index].id\n    |----------------\n    | aws_ec2_transit_gateway_route_table.route is tuple with 1 element\n    | count.index is 1\n\nThe given key does not identify an element in this collection value.\n\n&quot;,</p>