title: Terraform multiple for_each resources
body: <p>I've created multiple subnets and multiple VPC endpoints using the <code>for_each</code> loop as follows:</p>
  
  <pre><code>### VARIABLES ###
  
  variable "private_cidr_mask" {
    default = {
      "us-west-1a" = "10.0.1.0/24"
      "us-west-1b" = "10.0.2.0/24"
    }
  }
  
  variable "vpc_endpoints" {
    default = [
      "com.amazonaws.us-west-1.ecs-agent",
      "com.amazonaws.us-west-1.ecs-telemetry",
      "com.amazonaws.us-west-1.ecs"
    ]
  }
  
  ### RESOURCES ###
  
  resource "aws_subnet" "private_subnet" {
  
    for_each = var.private_cidr_mask
  
    vpc_id = aws_vpc.vpc.id
    availability_zone = each.key
    cidr_block = each.value
  }
  
  resource "aws_vpc_endpoint" "vpc_endpoint" {
  
    for_each = toset(var.vpc_endpoints)
  
    vpc_id = aws_vpc.vpc.id
    vpc_endpoint_type = "Interface"
    service_name = each.value
  
    security_group_ids = [ aws_security_group.security_group.id ]
  
    private_dns_enabled = true
  }
  
  </code></pre>
  
  <p>Now I have to assign every VPC endpoint to each of the private subnets using a <code>aws_vpc_endpoint_subnet_association</code>:</p>
  
  <pre><code>resource "aws_vpc_endpoint_subnet_association" "vpc_endpoint_subnet_association" {
    vpc_endpoint_id = &lt;every endpoint&gt;
    subnet_id = &lt;every subnet&gt;
  }
  </code></pre>
  
  <p>How do I achieve this in Terraform? I have tried nested for_each loops without success.</p>