Azure - get a ID from vnet

hi everyone

i try to find out, how i can get in my main.tf file, where i make a vnet peering, after i have create a Azure AADDS, my remote_virtual_network_id. I dont want to hardcode that, so how i can get this info into a output or variable or something similar?

my code now is:

resource “azurerm_virtual_network_peering” “vnetpeering1” {
name = “N4K-TO-AADS”
resource_group_name = var.rg
virtual_network_name = var.vnet-n4k
remote_virtual_network_id = “/subscriptions/blablabla/aadds-vnet”
allow_virtual_network_access = true
allow_forwarded_traffic = true
}

resource “azurerm_virtual_network_peering” “vnetpeering2” {
name = “AADS-TO-N4K”
resource_group_name = var.rg
virtual_network_name = var.vnet-aadds
remote_virtual_network_id = “/subscriptions/blablabla/n4k-v01-we-vn-001”
allow_virtual_network_access = true
allow_forwarded_traffic = true

i dont make that in the same step as i create all the other ressources, because AADD i must create seperate, and than i must peer that vnet with my own vnet. so i must find i way to get the correct .ID from my subscription than. anyone who can help?

regards
frank

Use terraform import to import the vnet into the terraform state, and then reference it as a normal terraform resource.

Let’s say I imported an existing vnet as “vnet-manuallabor” and one as “vnet-adgoeshere”.

name = “N4K-TO-AADS”
resource_group_name = var.rg
virtual_network_name = "${azurerm_virtual_network.vnet-manuallabor.name}"
remote_virtual_network_id = "${azurerm_virtual_network.vnet-adgoeshere.name}"
allow_virtual_network_access = true
allow_forwarded_traffic = true
}

resource “azurerm_virtual_network_peering” “vnetpeering2” {
name = “AADS-TO-N4K”
resource_group_name = var.rg
virtual_network_name = "${azurerm_virtual_network.vnet-adgoeshere.name}"
remote_virtual_network_id = "${azurerm_virtual_network.vnet-manuallabor.name}"
allow_virtual_network_access = true
allow_forwarded_traffic = true

Virtual machines are operating systems that emulate the physical operating system. Almost all parts, virtual machines are the same as their physical counterpart, with some exceptions. There is a number of platforms to host your virtual machines on. For example, Microsoft Hyper-V and VMWare are the two major players in the space. Virtual machines can also be hosted on the cloud service, such as Microsoft Azure or Amazon Web Services.
You can find more detail Microsoft Virtual Machine.