title: Get ip adress and hostname output in terraform
body: <p>So I start to explore Terraform, and so far Im able to get my network and VMs up in Azure.
  Since I have seven VM`s that are created, I would like to get the IP-adress and the Hostname of this.</p>
  <p>In my main.tf i have this:</p>
  <pre><code>provider &quot;azurerm&quot; {
    features {}
    # Configuration options
  }
  
  
  
  module &quot;splunk_architect&quot; {  
    source = &quot;./modules/architect&quot;
    
  }
  </code></pre>
  <p>And just an example from my main.tf in /modules/architect</p>
  <pre><code>resource &quot;azurerm_network_interface&quot; &quot;main&quot; {
      for_each = toset(var.vm_names)
    name                = &quot;${each.value}-nic&quot;
    location            = azurerm_resource_group.rsg.location
    resource_group_name = azurerm_resource_group.rsg.name
  
  
    ip_configuration {
      name                          = &quot;testconfiguration1&quot;
      subnet_id                     = azurerm_subnet.subnet.id
      private_ip_address_allocation = &quot;Dynamic&quot;
      public_ip_address_id          = azurerm_public_ip.pubip[each.key].id
    }
  </code></pre>
  <p>And my outputs.tf in /modules/architect</p>
  <pre><code>output &quot;ip&quot; {
    value = azurerm_network_interface.main[each.key].private_ip_address
  }
  </code></pre>
  <p>So when i run this, i get this error message:</p>
  <pre><code>Error: Reference to &quot;each&quot; in context without for_each
  
    on modules\architect\outputs.tf line 6, in output &quot;ip&quot;:    6:   value = azurerm_network_interface.main[each.key].private_ip_address
  
  The &quot;each&quot; object can be used only in &quot;module&quot; or &quot;resource&quot; blocks, and only when the &quot;for_each&quot; argument is set.
  </code></pre>
  <p>So I have tried to set the for_each in the module, but did not get that to work.
  I have also been through the documentations without any success.
  Any tips to what I can try to get the IP of each VM printed out?</p>