title: Terraform - iterate over combined map and list
body: <p>I would like to use Terraform to combine a list and a map into a set of resource arguments for an AWS security group. For each port in the list of ports, and for each key in the map of people I would like to have an Ingress rule in the security group. So for example I have a (simplified) .tf like this (question marks where I don't know):</p>
  <pre><code>variable &quot;IP_Mapping&quot; {
    type = &quot;map&quot;
    default = {
      &quot;bob&quot;          = &quot;1.1.1.1/32&quot;
      &quot;alice&quot;        = &quot;2.2.2.2/32&quot;
    }
  }
  
  variable &quot;ingress_ports&quot; {
    type        = list(number)
    description = &quot;list of ingress ports&quot;
    default     = [80, 443]
  }
  
  resource &quot;aws_security_group&quot; &quot;sg-vpc&quot; {
    name        = &quot;sd-ocp-vpc_sg&quot;
    description = &quot;Default security group&quot;
    vpc_id      = &quot;${aws_vpc.vpc.id}&quot;
  
      ingress {
        from_port   = ?
        to_port     = ?
        protocol    = &quot;tcp&quot;
        cidr_blocks = ?
        description = ?
      }
  }
  </code></pre>
  <p>And I would like a resulting static resource like this:</p>
  <pre><code>resource &quot;aws_security_group&quot; &quot;sg-vpc&quot; {
    name        = &quot;sd-ocp-vpc_sg&quot;
    description = &quot;Default security group&quot;
    vpc_id      = &quot;${aws_vpc.vpc.id}&quot;
  
    ingress {
      from_port   = 80
      to_port     = 80
      protocol    = &quot;tcp&quot;
      cidr_blocks = [&quot;1.1.1.1/32&quot;]
      description = &quot;bob&quot;
    }
    ingress {
      from_port   = 443
      to_port     = 443
      protocol    = &quot;tcp&quot;
      cidr_blocks = [&quot;1.1.1.1/32&quot;]
      description = &quot;bob&quot;
    }
    ingress {
      from_port   = 80
      to_port     = 80
      protocol    = &quot;tcp&quot;
      cidr_blocks = [&quot;2.2.2.2/32&quot;]
      description = &quot;alice&quot;
    }
    ingress {
      from_port   = 443
      to_port     = 443
      protocol    = &quot;tcp&quot;
      cidr_blocks = [&quot;2.2.2.2/32&quot;]
      description = &quot;alice&quot;
    }
  }
  </code></pre>
  <p>I realize that the order of the ingress blocks doesn't matter. I'm also not overly attached to the map/list data structure if there's a better way I'm not seeing, as long as I don't have to list each port for each user (there may be many ports, but they'll always be the same for all users).</p>
  <p>I have gotten as far as using dynamic blocks for the ingress rule, and can figure out how to iterate over the map in the dynamic block, but can't for the life of my figure out how to get a nested for loop in a dynamic resource argument to work.</p>