title: How do I get a list from a for expression in Terraform?
body: <p>According to <a href="https://www.terraform.io/docs/language/expressions/for.html" rel="nofollow noreferrer">the documentation</a>, Terraform <code>for</code> expressions can produce either maps or tuples.</p>
  <p>However I end up with the following when I try to use the value in a <code>for_each</code>:</p>
  <pre><code>flatten([ for service in var.services: service.subdomains ])
  # or
  flatten(tolist([ for service in var.services: service.subdomains ]))
  # or
  tolist(flatten([ for service in var.services: service.subdomains ]))
  </code></pre>
  <pre><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 tuple.
  </code></pre>
  <hr />
  <p>The value for <code>services</code> is as follows:</p>
  <pre><code>  [
      {
        name = &quot;some-name&quot;,
        backend = module.some_module.some_resource,
        subdomains = [
          &quot;subdomainone&quot;,
          &quot;subdomaintwo&quot;,
        ],
      },
    ]
  </code></pre>
  <hr />
  <p><a href="https://gist.github.com/atrauzzi/0019ac662f5493d107e0d7c8b31ca72d" rel="nofollow noreferrer">Here is a minimal repro:</a></p>
  <pre><code>locals {
    services = [
      {
        name = &quot;some-name&quot;,
        subdomains = [
          &quot;subdomainone&quot;,
          &quot;subdomaintwo&quot;,
        ],
      },
    ]
  }
  
  resource local_file &quot;whatever&quot; {
  
    for_each = setproduct([ &quot;one&quot; ], flatten([ for service in local.services: service.subdomains ]))
  
    filename = &quot;whatever&quot;
  }
  
  output services {
    value = local.services
  }
  
  output flatten {
    value = flatten([ for service in local.services: service.subdomains ])
  }
  
  output setproduct {
    value = setproduct([ &quot;one&quot; ], flatten([ for service in local.services: service.subdomains ]))
  }
  
  </code></pre>
  <hr />
  <p>Is there any way in Terraform to convert a tuple to a list?</p>
  <p><em>(Sidenote: It seems strange that Terraform wouldn't return a list from a for expression instead of a tuple...)</em></p>