Vnet 对等互连在 azure 中未被删除
我正在尝试使用 terraform 在 azure 中创建/删除 vnet 对等连接。为了提供一些上下文,有两个 vnet - A 和 B,在两个不同的订阅下,但在同一 AD 中,我可以访问这两个网络。 Vnet A 是静态的,vnetB 是按需创建的。
我能够通过从 vnet B 启动来创建对等互连。但是,当我从 Vnet B 删除对等互连并删除 vNet B 的整个资源组并重新创建资源组和对等互连时,它会显示 -
Error: Cannot create or update peering vnetB. Virtual networks -vnetB and vnetA cannot be peered because address space of the first virtual network overlaps with address space of vnet already peered with the second virtual network. Overlapping address prefixes: 10.2.65.0/25.
我可以看到对等互连未从vnet A. 有没有办法删除这个对等互连?
地形文件:
# It is assumed that A already has a resource group and vnet created
# Access the static A account
provider "azurerm" {
alias = "A"
subscription_id = "XXXX-XXXX-XXXX"
features {}
skip_provider_registration = true
}
data "azurerm_resources" "vnet" {
resource_group_name = "A-ResourceGroup"
type = "Microsoft.Network/virtualNetworks"
provider = azurerm.Aprov
}
resource "azurerm_virtual_network_peering" "A-B" {
provider = azurerm.Aprov
name = "A-B"
resource_group_name = data.azurerm_resources.vnet.resource_group_name
virtual_network_name = data.azurerm_resources.vnet.resources[0].name
remote_virtual_network_id = azurerm_virtual_network.B-vnet.id
}
# Deployment in B Account
provider "azurerm" {
skip_provider_registration = true
features {}
}
resource "azurerm_resource_group" "B" {
name = "B-peer-1"
location = "West US"
}
resource "azurerm_virtual_network" "B-vnet" {
name = "B-network1"
resource_group_name = azurerm_resource_group.B.name
address_space = ["10.0.1.0/24"]
location = "West US"
}
# Add the VNET peering to A account
resource "azurerm_virtual_network_peering" "B-A" {
name = "B-A"
resource_group_name = azurerm_resource_group.B.name
virtual_network_name = azurerm_virtual_network.B-vnet.name
remote_virtual_network_id = data.azurerm_resources.vnet.resources[0].id
}
I am trying to create/delete vnet peering connection in azure using terraform. To provide some context, there are two vnets- A and B, under two different subscription but within same AD and I have access to both. Vnet A is static and vnetB is created on-demand.
I am able to create the peering by initiating from vnet B. But when I delete the peering from Vnet B and delete the entire resource group of vNet B and recreate the resource group and peering, it says-
Error: Cannot create or update peering vnetB. Virtual networks -vnetB and vnetA cannot be peered because address space of the first virtual network overlaps with address space of vnet already peered with the second virtual network. Overlapping address prefixes: 10.2.65.0/25.
I can see peering is not deleted from vnet A. Is there a way to delete this peering ?
Terraform file:
# It is assumed that A already has a resource group and vnet created
# Access the static A account
provider "azurerm" {
alias = "A"
subscription_id = "XXXX-XXXX-XXXX"
features {}
skip_provider_registration = true
}
data "azurerm_resources" "vnet" {
resource_group_name = "A-ResourceGroup"
type = "Microsoft.Network/virtualNetworks"
provider = azurerm.Aprov
}
resource "azurerm_virtual_network_peering" "A-B" {
provider = azurerm.Aprov
name = "A-B"
resource_group_name = data.azurerm_resources.vnet.resource_group_name
virtual_network_name = data.azurerm_resources.vnet.resources[0].name
remote_virtual_network_id = azurerm_virtual_network.B-vnet.id
}
# Deployment in B Account
provider "azurerm" {
skip_provider_registration = true
features {}
}
resource "azurerm_resource_group" "B" {
name = "B-peer-1"
location = "West US"
}
resource "azurerm_virtual_network" "B-vnet" {
name = "B-network1"
resource_group_name = azurerm_resource_group.B.name
address_space = ["10.0.1.0/24"]
location = "West US"
}
# Add the VNET peering to A account
resource "azurerm_virtual_network_peering" "B-A" {
name = "B-A"
resource_group_name = azurerm_resource_group.B.name
virtual_network_name = azurerm_virtual_network.B-vnet.name
remote_virtual_network_id = data.azurerm_resources.vnet.resources[0].id
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了重现您的问题,请在同一区域中创建 VNETA 和 VNET B 并对它们进行对等
VNETA 到 VNETB 对等互连 >

VNETB 到 VNETA 对等互连
现在我删除了
VNETB
,但仍然除非我们不删除或移除对等互连,否则它将与 VNETA 对等互连。但是,您正在创建相同的 VNETB 或使用不同的名称但具有相同的地址空间,它会说您无法对等,因为您已经在对等中,并且会抛出像您遇到的错误。
您可以从门户本身删除现有对等互连。
您还可以使用 terraform 命令销毁现有的对等互连<代码>terraform destroy -target nameofpeering
For reproducing your issue create a VNETA and VNET B in the same region and peer them as well
VNETA to VNETB Peering

VNETB to VNETA Peering
Now i deleted the
VNETB
, But still it will be peer withVNETA
untill unless we don't delete or remove peering.But, you are creating the same VNETB or with different name but with the same address space it will say you can't peer because you already in peer and will throw the error like you are getting.
You can delete the Existing Peering from portal itself.
You can also use terraform command to destroy the existing peering
terraform destroy -target nameofpeering