title: Terraform: modules + output from for_each
body: <p>I have a Terraform script using modules. I want to create multiple resources so I'm using the for_each method.</p>
  <p>Below is my variable configuration:</p>
  <pre><code>variable bridge_domains {
    description = &quot;Bridge Domain&quot;
    type     = map
    default  = {
      bd1 = {
        name  = &quot;BD1&quot;,
      },
      bd2 = {
        name    = &quot;BD2&quot;
      }
    }
  }
  </code></pre>
  <p>In the root <code>main.tf</code> file, I'm looping over that variable using <code>for_each</code>:</p>
  <pre><code>module &quot;schema_template_bd&quot; {
    source = &quot;./modules/schema_template_bd&quot;
    for_each     =    var.bridge_domains
    
    schema       =    module.tenant.mso_schema.id 
    template     =    var.template
  
    bd           =    each.value.name
  }
  </code></pre>
  <p>Then in the <code>modules/schema_template_bd</code> file I have the following:</p>
  <pre><code>resource &quot;mso_schema_template_bd&quot; &quot;bd&quot; {
    schema_id              =      var.schema
    template_name          =      var.template
    name                   =      var.bd
  }
  </code></pre>
  <p>The module has an output where I have defined the following:</p>
  <pre><code>output &quot;mso_bd&quot; {
    value = mso_schema_template_bd.bd[*]
  }
  </code></pre>
  <p>The idea is to output the names from all the objects that were created. So I have defined an <code>output.tf</code> file (at root level) containing the following code:</p>
  <pre><code>output &quot;bd_name&quot; {
    value = module.schema_template_bd.mso_bd.*.name
  }
  </code></pre>
  <p>I always get:</p>
  <blockquote>
  <p>This object does not have an attribute named &quot;name&quot;.</p>
  </blockquote>
  <p>Normally the <code>bd</code> object has a name so the error has to do with a wrong syntax in my view.</p>