I deployed vnet peerings with terraform. But it was stuck on initiated status. When i tried manually with same values there was no problem. How can i fix it?
resource "azurerm_virtual_network_peering" "spoke_aks_peering" {
virtual_network_name = azurerm_virtual_network.virtual_network_spoke.name
resource_group_name = azurerm_resource_group.resource-group_spoke.name
remote_virtual_network_id = azurerm_virtual_network.virtual_network_aks.id
name = "peerspoketoaks"
allow_virtual_network_access = true
allow_forwarded_traffic = true
}
CodePudding user response:
I tried to reproduce the same in my environment to create a peering between 2 virtual networks:
Note: If the Peering Status is currently Initiated because we need to do the same peering on the other virtual network to get the status connected.
To resolve the Issue, create peering on both the VNet, like below.
#Azure Virtual Network peering between Virtual Network stagingtotest and testtostaging
resource "azurerm_virtual_network_peering" "peeringconnection1" {
name = "stagingtotest"
resource_group_name = local.resource_group_name
virtual_network_name = azurerm_virtual_network.network["staging"].name
remote_virtual_network_id = azurerm_virtual_network.network["test"].id
}
#Azure Virtual Network peering between Virtual Network testtostaging and stagingtotest
resource "azurerm_virtual_network_peering" "peeringconnection2" {
name = "testtostaging"
resource_group_name = local.resource_group_name
virtual_network_name = azurerm_virtual_network.network["test"].name
remote_virtual_network_id = azurerm_virtual_network.network["staging"].id
}
After Terraform apply, Peering created on both the Vnets.
Refer the document here for more.