gpt4 book ai didi

azure - Terraform Vnet 与不同资源组中的 VLAN 进行对等互连

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

我对 Terraform 很陌生,所以也许我犯了一个非常基本的错误,但几个小时后也许有人可以帮助我。

所以我尝试一起对等 VLAN。我查看了多个有关它的教程,我看到的配置之间的唯一区别是我想在 2 个不同资源组中的 2 个 VLAN 之间进行对等互连。我还注意到,如果我将对等互连放入 2 个 VLAN 资源组之一,我会出现发热错误。

error

#Creating Resource Groups
resource "azurerm_resource_group" "network" {
name = "network"
location = "West Europe"
}

resource "azurerm_resource_group" "front" {
name = "front"
location = "West Europe"
}

resource "azurerm_resource_group" "middle" {
name = "middle"
location = "West Europe"
}

resource "azurerm_resource_group" "back" {
name = "back"
location = "West Europe"
}

resource "azurerm_resource_group" "peerings" {
name = "peerings"
location = "West Europe"
}


#Creating Virtual Networks
resource "azurerm_virtual_network" "network" {
name = "network"
location = azurerm_resource_group.network.location
resource_group_name = azurerm_resource_group.network.name
address_space = ["10.1.0.0/16"]

subnet {
name = "default"
address_prefix = "10.1.0.0/24"
}

subnet {
name = "gatewaysubnet"
address_prefix = "10.1.1.0/24"
}

subnet {
name = "azurefirewallsubnet"
address_prefix = "10.1.3.0/24"
}

subnet {
name = "azurebastionsubnet"
address_prefix = "10.1.2.0/24"
}
}

resource "azurerm_virtual_network" "front" {
name = "network"
location = azurerm_resource_group.front.location
resource_group_name = azurerm_resource_group.front.name
address_space = ["10.2.0.0/16"]
}

resource "azurerm_virtual_network" "middle" {
name = "network"
location = azurerm_resource_group.middle.location
resource_group_name = azurerm_resource_group.middle.name
address_space = ["10.3.0.0/16"]
}

resource "azurerm_virtual_network" "back" {
name = "network"
location = azurerm_resource_group.back.location
resource_group_name = azurerm_resource_group.back.name
address_space = ["10.4.0.0/16"]
}

#Create peerings
#network <--> front
resource "azurerm_virtual_network_peering" "networktofront" {
name = "networktofront"
resource_group_name = azurerm_resource_group.peerings.name
virtual_network_name = azurerm_virtual_network.network.name
remote_virtual_network_id = azurerm_virtual_network.front.id
}

resource "azurerm_virtual_network_peering" "fronttonetwork" {
name = "fronttonetwork"
resource_group_name = azurerm_resource_group.peerings.name
virtual_network_name = azurerm_virtual_network.front.name
remote_virtual_network_id = azurerm_virtual_network.network.id
}

#network <--> middle
resource "azurerm_virtual_network_peering" "networktomiddle" {
name = "networktomiddle"
resource_group_name = azurerm_resource_group.peerings.name
virtual_network_name = azurerm_virtual_network.network.name
remote_virtual_network_id = azurerm_virtual_network.middle.id
}

resource "azurerm_virtual_network_peering" "middletonetwork" {
name = "middletonetwork"
resource_group_name = azurerm_resource_group.peerings.name
virtual_network_name = azurerm_virtual_network.middle.name
remote_virtual_network_id = azurerm_virtual_network.network.id
}

#network <--> back
resource "azurerm_virtual_network_peering" "networktoback" {
name = "networktoback"
resource_group_name = azurerm_resource_group.peerings.name
virtual_network_name = azurerm_virtual_network.network.name
remote_virtual_network_id = azurerm_virtual_network.back.id
}

resource "azurerm_virtual_network_peering" "backtonetwork" {
name = "backtonetwork"
resource_group_name = azurerm_resource_group.peerings.name
virtual_network_name = azurerm_virtual_network.back.name
remote_virtual_network_id = azurerm_virtual_network.network.id
}

最佳答案

虚拟网络对等互连是虚拟网络资源 (Microsoft.Network/virtualNetworks/network/virtualNetworkPeerings) 的子集,因此无法将它们划分为不同的资源组。

除此之外,您的代码是准确的,并且在相应的虚拟网络资源组中创建对等互连后就应该可以正常工作:

#Creating Resource Groups
resource "azurerm_resource_group" "network" {
name = "network"
location = "West Europe"
}

resource "azurerm_resource_group" "front" {
name = "front"
location = "West Europe"
}

resource "azurerm_resource_group" "middle" {
name = "middle"
location = "West Europe"
}

resource "azurerm_resource_group" "back" {
name = "back"
location = "West Europe"
}


#Creating Virtual Networks
resource "azurerm_virtual_network" "network" {
name = "network"
location = azurerm_resource_group.network.location
resource_group_name = azurerm_resource_group.network.name
address_space = ["10.1.0.0/16"]

subnet {
name = "default"
address_prefix = "10.1.0.0/24"
}

subnet {
name = "gatewaysubnet"
address_prefix = "10.1.1.0/24"
}

subnet {
name = "azurefirewallsubnet"
address_prefix = "10.1.3.0/24"
}

subnet {
name = "azurebastionsubnet"
address_prefix = "10.1.2.0/24"
}
}

resource "azurerm_virtual_network" "front" {
name = "network"
location = azurerm_resource_group.front.location
resource_group_name = azurerm_resource_group.front.name
address_space = ["10.2.0.0/16"]
}

resource "azurerm_virtual_network" "middle" {
name = "network"
location = azurerm_resource_group.middle.location
resource_group_name = azurerm_resource_group.middle.name
address_space = ["10.3.0.0/16"]
}

resource "azurerm_virtual_network" "back" {
name = "network"
location = azurerm_resource_group.back.location
resource_group_name = azurerm_resource_group.back.name
address_space = ["10.4.0.0/16"]
}

#Create peerings
#network <--> front
resource "azurerm_virtual_network_peering" "networktofront" {
name = "networktofront"
resource_group_name = azurerm_resource_group.network.name
virtual_network_name = azurerm_virtual_network.network.name
remote_virtual_network_id = azurerm_virtual_network.front.id
}

resource "azurerm_virtual_network_peering" "fronttonetwork" {
name = "fronttonetwork"
resource_group_name = azurerm_resource_group.front.name
virtual_network_name = azurerm_virtual_network.front.name
remote_virtual_network_id = azurerm_virtual_network.network.id
}

#network <--> middle
resource "azurerm_virtual_network_peering" "networktomiddle" {
name = "networktomiddle"
resource_group_name = azurerm_resource_group.network.name
virtual_network_name = azurerm_virtual_network.network.name
remote_virtual_network_id = azurerm_virtual_network.middle.id
}

resource "azurerm_virtual_network_peering" "middletonetwork" {
name = "middletonetwork"
resource_group_name = azurerm_resource_group.middle.name
virtual_network_name = azurerm_virtual_network.middle.name
remote_virtual_network_id = azurerm_virtual_network.network.id
}

#network <--> back
resource "azurerm_virtual_network_peering" "networktoback" {
name = "networktoback"
resource_group_name = azurerm_resource_group.network.name
virtual_network_name = azurerm_virtual_network.network.name
remote_virtual_network_id = azurerm_virtual_network.back.id
}

resource "azurerm_virtual_network_peering" "backtonetwork" {
name = "backtonetwork"
resource_group_name = azurerm_resource_group.back.name
virtual_network_name = azurerm_virtual_network.back.name
remote_virtual_network_id = azurerm_virtual_network.network.id
}

关于azure - Terraform Vnet 与不同资源组中的 VLAN 进行对等互连,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73892836/

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