title: Terraform Creating map dynamically using local variable instead of input variable
body: <p>Requirements: I have a bunch of EC2s. Which I am grouping according to the Tags. in this example total number of group =4 and each group has 7 EC2 : 1 parent-6 Child. here i am sharing code of child whose naming matters.</p>
  <p>working code:Here I am sharing the child EC2 code which is working perfectly fine with the input variables of map type  named :ws_to_Child_Node_name_map_count. Now i want it to be scalable(number of parent-child) for which I am looking to use 'dynamically created map in locals' instead of using input variable.
  main.tf</p>
  <pre><code>resource &quot;aws_instance&quot; &quot;ec2_instance_child&quot; {
    count                   = var.ec2_instance_child_count
    tags = {
      NodeName       = &quot;${lookup(var.ws_to_Child_Node_name_map_count, count.index+1, 99)}&quot;
    }
  }
  </code></pre>
  <p>variable.tf</p>
  <pre><code>variable &quot;ws_to_Child_Node_name_map_count&quot;  {
    type = map
    default = {
        &quot;1&quot;=&quot;1&quot;
        &quot;2&quot;=&quot;2&quot;
        &quot;3&quot;=&quot;3&quot;
        &quot;4&quot;=&quot;4&quot;
        &quot;5&quot;=&quot;5&quot;
        &quot;6&quot;=&quot;6&quot;
        &quot;7&quot;=&quot;1&quot;
        &quot;8&quot;=&quot;2&quot;
        &quot;9&quot;=&quot;3&quot;
        &quot;10&quot;=&quot;4&quot;
        &quot;11&quot;=&quot;5&quot;
        &quot;12&quot;=&quot;6&quot;
        &quot;13&quot;=&quot;1&quot;
        &quot;14&quot;=&quot;2&quot;
        &quot;15&quot;=&quot;3&quot;
        &quot;16&quot;=&quot;4&quot;
        &quot;17&quot;=&quot;5&quot;
        &quot;18&quot;=&quot;6&quot;
        &quot;19&quot;=&quot;1&quot;
        &quot;20&quot;=&quot;2&quot;
        &quot;21&quot;=&quot;3&quot;
        &quot;22&quot;=&quot;4&quot;
        &quot;23&quot;=&quot;5&quot;
        &quot;24&quot;=&quot;6&quot;
      }
    }
  variable &quot;ec2_instance_child_count&quot; {
    description = &quot;Number of instances to run&quot;
    default     = &quot;24&quot;   #number of group *6
  }
  </code></pre>
  <p>the map shown above I want to create dynamically using two variables, which in future i will not be constant.</p>
  <pre><code>variable &quot;child_count&quot; {
    default     = 6
  }
  
  variable &quot;group_count&quot; {
    default     =  4
  }
  </code></pre>