title: Terraform - For_each - You have provided a value of type list of object
body: <p>I get the following error when try out for_each (which is a type of list of objects) but the same thing works fine in a  dynamic block.</p>
  <p>Here is the error:</p>
  <p><code>The given &quot;for_each&quot; argument value is unsuitable: the &quot;for_each&quot; argument must be a map, or set of strings, and you have provided a value of type list of object.</code></p>
  <p>This is the module where I get the error</p>
  <pre><code>      vpc_subnets = [
          {name: &quot;public_test_a&quot;, cidr_block: &quot;10.0.0.0/28&quot;, map_public_ip_on_launch: true,  availability_zone: &quot;ap-south-1a&quot;},
          {name: &quot;public_test_b&quot;, cidr_block: &quot;10.0.0.16/28&quot;, map_public_ip_on_launch: true,  availability_zone: &quot;ap-south-1b&quot;},
          {name: &quot;private_test_a&quot;, cidr_block: &quot;10.0.0.32/28&quot;, map_public_ip_on_launch: false,  availability_zone: &quot;ap-south-1a&quot;},
          {name: &quot;private_test_b&quot;, cidr_block: &quot;10.0.0.48/28&quot;, map_public_ip_on_launch: false,  availability_zone: &quot;ap-south-1b&quot;}
        ]
  
  # Create Subnets
  resource &quot;aws_subnet&quot; &quot;subnets&quot; {
      for_each = var.vpc_subnets
  
      vpc_id = aws_vpc.vpc.id
      cidr_block = each.value.cidr_block
      map_public_ip_on_launch = each.value.map_public_ip_on_launch
      availability_zone = each.value.availability
  
      tags = merge({
        Name = each.value.name
      }, var.subnet_tags)
  }
  </code></pre>
  <p>But in another module, it works fine. The only difference is that its in a dynamic block.</p>
  <pre><code>  ingress_rules = [
      {description: &quot;Port 3306&quot;, cidr_blocks: [&quot;10.0.0.0/24&quot;, &quot;10.0.4.0/24&quot;], port: 3306, protocol: &quot;tcp&quot;},
      {description: &quot;Port 22&quot;,   cidr_blocks: [&quot;0.0.0.0/0&quot;], port: 22, protocol: &quot;tcp&quot;},
      {description: &quot;port 80&quot;,   cidr_blocks: [&quot;0.0.0.0/0&quot;], port: 80, protocol: &quot;tcp&quot;}
    ]
  
  resource &quot;aws_security_group&quot; &quot;security_group&quot; {
    name = var.name
  
    dynamic &quot;ingress&quot; {
      for_each = var.ingress_rules
  
      content {
        description = ingress.value.description
        cidr_blocks = ingress.value.cidr_blocks
        from_port   = ingress.value.port
        to_port     = ingress.value.port
        protocol    = ingress.value.protocol
      }
    }
   }
  </code></pre>