title: Variable values in Terraform for aws security groups
body: <p>I am new to terraform and trying to create an AWS security group with ingress and egress rules. Rather than hardcoding the values and creating multiple ingress and egress blocks, I am trying to make use of terraform <code>lookup</code> function.</p>
  <p><code>main.tf</code> file looks like this:</p>
  <pre><code>provider &quot;aws&quot; {
    version                 = &quot;~&gt; 2.0&quot;
    region                  = var.region
    profile                 = var.profile
  }
  
  resource &quot;aws_security_group&quot; &quot;this&quot; {
    name = &quot;test-sg&quot;
    description = &quot;test security group&quot;
  
    dynamic &quot;ingress&quot; {
      for_each = var.ingress_rules
      content {
        description      = lookup(ingress.value, &quot;description&quot;, null)
        from_port        = lookup(ingress.value, &quot;from_port&quot;, null)
        to_port          = lookup(ingress.value, &quot;to_port&quot;, null)
        protocol         = lookup(ingress.value, &quot;protocol&quot;, null)
        cidr_blocks      = lookup(ingress.value, &quot;cidr_blocks&quot;, null)
      }
    }
  
    egress {
      from_port   = 0
      to_port     = 0
      protocol    = &quot;-1&quot;
      cidr_blocks = [&quot;0.0.0.0/0&quot;]
    }
  
    tags = {
      Name = &quot;test-sg&quot;
    }
  }
  </code></pre>
  <p><code>variables.tf</code> file looks like this</p>
  <pre><code>variable &quot;ingress_rules&quot; {
    default     = {
      &quot;description&quot; = [&quot;For HTTP&quot;, &quot;For SSH&quot;]
      &quot;from_port&quot;   = [&quot;80&quot;, &quot;22&quot;]
      &quot;to_port&quot;     = [&quot;80&quot;, &quot;22&quot;]
      &quot;protocol&quot;    = [&quot;tcp&quot;, &quot;tcp&quot;]
      &quot;cidr_blocks&quot; = [&quot;0.0.0.0/0&quot;, &quot;0.0.0.0/0&quot;]
    }
    type        = map(list(string))
    description = &quot;Security group rules&quot;
  }
  </code></pre>
  <p>When I run <code>terraform validate</code> it shows configuration is valid, but when I run <code>terraform plan</code>, it shows the following error:</p>
  <pre><code> ingress.value is list of string with 2 elements
   
   Invalid value for &quot;inputMap&quot; parameter: lookup() requires a map as the first
   argument.
  </code></pre>
  <p>After spending a long time still, I am not able to figure out how to solve this error. What is the correct way to pass lookup values to <code>variables.tf</code> file.</p>