title: Terraform dynamically loop over elements in a list and expand based on values
body: <p>This is a bit hard to describe. So I have a map that looks like this after I've simplified it for clarity:</p>
  
  <pre><code>server_ip_configs = {
  mgmt        = {
      ct      = "1"
      }
  applicationgateway    = {
      ct      = "1"
      }
  monitor     = {
      ct      = "1"
      }
  app      = {
      ct      = "3"
      }
  }
  </code></pre>
  
  <p>What I want to do is iterate over the map to create a flat list where elements are multiplied by the number of the ct property into a new flat list.
  So we end up with a list that looks a bit like this:</p>
  
  <pre><code>server_ip_configs_mapped = [
         {
          name      = "mgmt-1"
          }
         {
          name      = "applicationgateway-1"
          }
         {
          name      = "monitor-1"
          }
         {
          name      = "app-1"
          }
         {
          name      = "app-2"
          }
         {
          name      = "app-3"
          }
  
      ]
  </code></pre>
  
  <p>Creating a list of elements for each row explicitly by setting a variable is trivial:</p>
  
  <pre><code>data "null_data_source" "server_list_ip_configs" {
    count = lookup(var.server_ip_configs[var.server_role], "ct", 0)
  
    inputs = {
      name    =   "${var.server_role}-${count.index +1}"
    }
  }
  </code></pre>
  
  <p>I can put this in a module and call multiple instances of the module and concat the results. But this is not a nice way to do it and not at all DRY. Am I right in thinking there is no other way of doing this in Terraform? Is it because terraform is essentially declarative and maybe I should declare a list with multiple instance in it rather than try and generate one? 
  Using a for loop won't work because you cant use an integer to iterate over explicitly from what I can see. So no:</p>
  
  <pre><code>for i in 5 
  </code></pre>
  
  <p>Any answers to this welcome. Thanks.</p>