title: A managed resource "azurerm_network_interface" "myterraformnic" has not been declared in module.vm. Azure
body: <p>I have created two modules:</p>
  <ol>
  <li><p>Network 2. VM
  In network.tf I have added network configuration thing for azure and in vm.tf I am trying to create a Virtual Machine. Calling both modules from main.tf I'm getting this error:</p>
  <p>on ..\modules\vm\vm.tf line 20, in resource &quot;azurerm_windows_virtual_machine&quot; &quot;myterraformvm&quot;:
  20:     network_interface_ids = [azurerm_network_interface.myterraformnic.id]</p>
  <p>A managed resource &quot;azurerm_network_interface&quot; &quot;myterraformnic&quot; has not been
  declared in module.vm.</p>
  </li>
  </ol>
  <p>This is the code of vm.tf</p>
  <pre><code>    # Resource Group
  resource &quot;azurerm_resource_group&quot; &quot;myterraformgroup&quot; {
      name     = &quot;myResourceGroup&quot;
      location = &quot;eastus&quot;
  }
  resource &quot;azurerm_image&quot; &quot;example&quot; {
    # (resource arguments)
   
    name     = &quot;WINDOWS2019C&quot;
    location = &quot;eastus&quot;
    resource_group_name = azurerm_resource_group.myterraformgroup.name
  }
  
  # Virtual Machine Properties
  
  resource &quot;azurerm_windows_virtual_machine&quot; &quot;myterraformvm&quot; {
      name                  = &quot;myVM&quot;
      location              = &quot;eastus&quot;
      resource_group_name   = azurerm_resource_group.myterraformgroup.name
      network_interface_ids = [azurerm_network_interface.myterraformnic.id]
      size                  = &quot;Standard_DS1_v2&quot;
      admin_username      = &quot;XXXXXXXXXXXXX&quot;
      admin_password      = &quot;XXXXXXXXXXXXXX&quot;
  
      os_disk {
          name              = &quot;myOsDisk&quot;
          caching           = &quot;ReadWrite&quot;
          storage_account_type = &quot;Premium_LRS&quot;
      }
      source_image_id = &quot;/subscriptions/XXXXXXXXXXXXXXXXXXX/soft.Compute/images/XXXXXXXX&quot;
  }
  </code></pre>
  <p>This is the code of network.tf</p>
  <pre><code> #Create virtual network
  resource &quot;azurerm_resource_group&quot; &quot;myterraformgroup&quot; {
      name     = &quot;myResourceGroup&quot;
      location = &quot;eastus&quot;
  }
  resource &quot;azurerm_virtual_network&quot; &quot;myterraformnetwork&quot; {
      name                = &quot;myVnet&quot;
      address_space       = [&quot;10.0.0.0/16&quot;]
      location            = &quot;eastus&quot;
      resource_group_name = azurerm_resource_group.myterraformgroup.name
  
      tags = {
          environment = &quot;Terraform Demo&quot;
      }
  }
  
  # Create subnet
  resource &quot;azurerm_subnet&quot; &quot;myterraformsubnet&quot; {
      name                 = &quot;mySubnet&quot;
      resource_group_name  = azurerm_resource_group.myterraformgroup.name
      virtual_network_name = azurerm_virtual_network.myterraformnetwork.name
      address_prefixes       = [&quot;10.0.1.0/24&quot;]
  }
  
  # Create public IPs
  resource &quot;azurerm_public_ip&quot; &quot;myterraformpublicip&quot; {
      name                         = &quot;myPublicIP&quot;
      location                     = &quot;eastus&quot;
      resource_group_name          = azurerm_resource_group.myterraformgroup.name
      allocation_method            = &quot;Dynamic&quot;
  
      tags = {
          environment = &quot;Terraform Demo&quot;
      }
  }
  
  # Create Network Security Group and rule
  resource &quot;azurerm_network_security_group&quot; &quot;myterraformnsg&quot; {
      name                = &quot;myNetworkSecurityGroup&quot;
      location            = &quot;eastus&quot;
      resource_group_name = azurerm_resource_group.myterraformgroup.name
  
      security_rule {
          name                       = &quot;HTTP&quot;
          priority                   = 1001
          direction                  = &quot;Inbound&quot;
          access                     = &quot;Allow&quot;
          protocol                   = &quot;Tcp&quot;
          source_port_range          = &quot;*&quot;
          destination_port_range     = &quot;*&quot;
          source_address_prefix      = &quot;*&quot;
          destination_address_prefix = &quot;*&quot;
      }
  
      tags = {
          environment = &quot;Terraform Demo&quot;
      }
  }
  
  # Create network interface
  resource &quot;azurerm_network_interface&quot; &quot;myterraformnic&quot; {
      name                      = &quot;myNIC&quot;
      location                  = &quot;eastus&quot;
      resource_group_name       = azurerm_resource_group.myterraformgroup.name
  
      ip_configuration {
          name                          = &quot;myNicConfiguration&quot;
          subnet_id                     = azurerm_subnet.myterraformsubnet.id
          private_ip_address_allocation = &quot;Dynamic&quot;
          public_ip_address_id          = azurerm_public_ip.myterraformpublicip.id
      }
  
      tags = {
          environment = &quot;Terraform Demo&quot;
      }
  }
  
  # Connect the security group to the network interface
  resource &quot;azurerm_network_interface_security_group_association&quot; &quot;example&quot; {
      network_interface_id      = azurerm_network_interface.myterraformnic.id
      network_security_group_id = azurerm_network_security_group.myterraformnsg.id
  }
  
  # Generate random text for a unique storage account name
  resource &quot;random_id&quot; &quot;randomId&quot; {
      keepers = {
          # Generate a new ID only when a new resource group is defined
          resource_group = azurerm_resource_group.myterraformgroup.name
      }
  
      byte_length = 8
  }
  </code></pre>
  <p>main.tf</p>
  <pre><code>provider &quot;azurerm&quot; {
      # The &quot;feature&quot; block is required for AzureRM provider 2.x.
      # If you're using version 1.x, the &quot;features&quot; block is not allowed.
      version = &quot;~&gt;2.0&quot;
      features {}
  }
  module &quot;modules&quot; {
      source = &quot;../modules/network&quot;
  }
  module &quot;vm&quot; {
      source = &quot;../modules/vm&quot;
  }
  </code></pre>
  <p>Directory Structure:</p>
  <pre><code>$ ls
  dev/  modules/
  $ ls dev/
  main.tf
  $ ls modules/
  network/  vm/
  </code></pre>