terraform-azurerm-virtual-machine icon indicating copy to clipboard operation
terraform-azurerm-virtual-machine copied to clipboard

Splitting vnet data and supporting different RGs for VM & VNet

Open tohewi opened this issue 3 years ago • 2 comments

Hi,

Instead of having local data on vnet:

data "azurerm_virtual_network" "vnet" {
  name                = var.virtual_network_name
  resource_group_name = data.azurerm_resource_group.rg.name
}

would you please consider having the possibility to provide network map as input to the module.

I am using a map like this to

locals {
  vnet_map = merge(
	var.vnet_map,
    {
    dev = {
      vnet = "${data.azurerm_virtual_network.pe_dev_vnet01.id}"
      default_subnet = "${data.azurerm_subnet.pe_dev_vnet01_subnet01.id}"
    }
    test = {
      vnet = "${data.azurerm_virtual_network.pe_test_vnet01.id}"
      default_subnet = "${data.azurerm_subnet.pe_test_vnet01_subnet01.id}"
    }
    prod = {
      vnet = "${data.azurerm_virtual_network.pe_prod_vnet01.id}"
      default_subnet = "${data.azurerm_subnet.pe_prod_vnet01_subnet01.id}"
    }
    },
  )
}

to create an environment specific map of vnet and subnet ids.

This would help keeping vnet data consistently in one "module" and also support cases where VNETs and VMs are in different resource groups.

tohewi avatar Nov 25 '21 20:11 tohewi

You can use meta arguments (for_each and count) with this module to achieve any requirement. This module is more of a general purpose and can be utilised for more complex scenarios using meta arguments. Please check this link for more information. https://www.terraform.io/language/meta-arguments/for_each

kumarvna avatar Feb 23 '22 06:02 kumarvna

Hi @kumarvna I don't think you understand the issue here. You can't use VNET for the VM if it's deployed in the different resource group. the module assumes that the VNET is deployed in the same resource group as the VM will be. subnet_id parameter would resolve this. This is preventing me from using this module.

jakubigla avatar Dec 21 '22 09:12 jakubigla