gpt4 book ai didi

azure - Vnet 对等互连在 azure 中未被删除

转载 作者:行者123 更新时间:2023-12-03 07:07:10 26 4
gpt4 key购买 nike

我正在尝试使用 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
}

最佳答案

为了重现您的问题,请在同一区域中创建 VNETA 和 VNET B,并对它们进行对等

VNETA 到 VNETB 对等互连 enter image description here

VNETB 到 VNETA 对等互连

enter image description here

现在我删除了 VNETB,但它仍然会与 VNETA 对等,除非我们不删除或删除对等互连。

但是,您正在创建相同的 VNETB 或使用不同的名称但具有相同的地址空间,它会说您无法对等,因为您已经在对等中,并且会抛出像您遇到的错误。

enter image description here

您可以从门户本身删除现有对等互连。

enter image description here

您还可以使用 terraform 命令销毁现有对等互连 terraform destroy -target nameofpeering

关于azure - Vnet 对等互连在 azure 中未被删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71221243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com