title: Terraform: Use Azure resource group from module in a different module
body: <p>I have successfully created a vnet module (with a resource group). But I'm now trying to create an azure public IP address in a compute module, but want to place it in the resource group I created in the vnet module. Please help.</p>
  <p>Folder Structure:</p>
  <pre><code>    c:\terraform
         -main
         -terraform.tfvars
         -variables.tf
      c:\terraform\modules\vnet
         -main
         -output
         -variables
      c:\terraform\modules\compute
        -main
        -variables
        -output
  </code></pre>
  <p>contents of c:\terraform\main.tf</p>
  <pre><code>terraform {
    required_providers {
      azurerm = {
        source  = &quot;hashicorp/azurerm&quot;
        version = &quot;=2.68.0&quot;
      }
    }
    backend &quot;azurerm&quot; {
      resource_group_name  = &quot;rg-terraform&quot;
      storage_account_name = &quot;terraform85&quot;
      container_name       = &quot;tfstate&quot;
      key                  = &quot;terraform.tfstate&quot;
    }
  
  }
  
  provider &quot;azurerm&quot; {
    features {}
  }
  
  
  resource &quot;azurerm_resource_group&quot; &quot;compute&quot; {
    name     = &quot;rg-compute&quot;
    location = var.location
  }
  
  resource &quot;azurerm_resource_group&quot; &quot;storage&quot; {
    name     = &quot;rg-storage&quot;
    location = var.location
  }
  
  #Call vnet child module
  module &quot;azure-vnet&quot; {
    source = &quot;./modules/vnet/&quot;
  
  }
  
  #Call compute child module
  module &quot;azure-compute&quot; {
    source = &quot;./modules/compute/&quot;
  
  }
  </code></pre>
  <p>contents of c:\terraform\variables.tf</p>
  <pre><code>variable &quot;location&quot; {
    type = string
  }
  </code></pre>
  <p>contents of c:\terraform\terraform.tfvars</p>
  <pre><code>location = &quot;UK South&quot;
  </code></pre>
  <p>contents of c:\terraform\modules\vnet\main.tf:</p>
  <pre><code>#This module will create a Azure resource group
  #1 virtual network
  #3 subnets. 
  
  
  resource &quot;azurerm_resource_group&quot; &quot;network&quot; {
    name     = &quot;rg-network&quot;
    location = var.location
  }
  
  resource &quot;azurerm_virtual_network&quot; &quot;vnet&quot; {
    name                = var.vnet_name
    location            = azurerm_resource_group.network.location
    resource_group_name = azurerm_resource_group.network.name
    address_space       = var.address_space
  }
  
  resource &quot;azurerm_subnet&quot; &quot;subnet1&quot; {
    name                 = &quot;AzureBastionSubnet&quot;
    resource_group_name  = azurerm_resource_group.network.name
    virtual_network_name = azurerm_virtual_network.vnet.name
    address_prefixes     = [&quot;172.16.0.0/27&quot;]
  }
  
  resource &quot;azurerm_subnet&quot; &quot;subnet2&quot; {
    name                 = &quot;subnet-web&quot;
    resource_group_name  = azurerm_resource_group.network.name
    virtual_network_name = azurerm_virtual_network.vnet.name
    address_prefixes     = [&quot;172.16.0.32/27&quot;]
  }
  
  resource &quot;azurerm_subnet&quot; &quot;subnet3&quot; {
    name                 = &quot;subnet-app&quot;
    resource_group_name  = azurerm_resource_group.network.name
    virtual_network_name = azurerm_virtual_network.vnet.name
    address_prefixes     = [&quot;172.16.0.64/27&quot;]
  }
  
  resource &quot;azurerm_subnet&quot; &quot;subnet4&quot; {
    name                 = &quot;subnet-core&quot;
    resource_group_name  = azurerm_resource_group.network.name
    virtual_network_name = azurerm_virtual_network.vnet.name
    address_prefixes     = [&quot;172.16.0.96/27&quot;]
  }
  
  resource &quot;azurerm_subnet&quot; &quot;subnet5&quot; {
    name                 = &quot;subnet-data&quot;
    resource_group_name  = azurerm_resource_group.network.name
    virtual_network_name = azurerm_virtual_network.vnet.name
    address_prefixes     = [&quot;172.16.0.128/27&quot;]
  }
  </code></pre>
  <p>contents of C:\terraform\modules\vnet\output.tf</p>
  <pre><code>output &quot;ResourceGroupid&quot; {
      description = &quot;id of the resource group provisioned&quot;
      value = azurerm_resource_group.network.name
  }
  </code></pre>
  <p>contents of c:\terraform\modules\vnet\variables.tf:</p>
  <pre><code>variable &quot;location&quot; {
      type = string
      default = &quot;UK South&quot;
    
  }
  variable &quot;vnet_name&quot;{
  default = &quot;core-vnet&quot;
  }
  
  variable &quot;address_space&quot;{
  default = [&quot;172.16.0.0/22&quot;]
  }
  
  
  </code></pre>
  <p>contents of c:\terraform\modules\compute\main.tf</p>
  <pre><code>#This module will create an Azure VM
  
  module &quot;azure-vnet2&quot; {
   source = &quot;../../modules/vnet&quot;
   name = azurerm_resource_group.network.name
   location = &quot;UK South&quot;
    
  }
  
  ## Create public IP address. Place in the resource group created in the vnet module block - Network resource group.
  resource   &quot;azurerm_public_ip&quot;   &quot;myvm1publicip&quot;   { 
     name   =   &quot;pip-vm-dc01&quot; 
     location   =   &quot;UK South&quot; 
     resource_group_name   =   module.azure-vnet2.name
     allocation_method   =   &quot;Dynamic&quot; 
     sku   =   &quot;Basic&quot; 
   } 
  </code></pre>
  <p>When I run Terraform plan, I get the following error. I know that the compute module is horribly wrong, but I can't figure out what..</p>
  <pre><code>PS C:\Users\xxxxxxxxx\xxxx&gt; terraform plan
  
  ╷
  │ Error: Unsupported argument
  │
  │   on modules\compute\main.tf line 5, in module &quot;azure-vnet2&quot;:
  │    5:  name = azurerm_resource_group.network.name
  │
  │ An argument named &quot;name&quot; is not expected here.
  </code></pre>