gpt4 book ai didi

azure - 来自内联虚拟网络资源的子网 ID

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

我正在使用 Terraform 创建虚拟网络,并且子网是在虚拟网络资源 block 内创建的(而不是使用其自己的资源 block )。

我正在尝试将一些路由表关联到子网,但是我不确定在虚拟网络中创建子网时如何获取子网资源 ID,有人可以帮忙吗?

ma​​in.tf

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.24.0"
}
}
}

provider "azurerm" {
skip_provider_registration = true
features {}
}

###########################
# RESOURCE GROUP CREATION #
###########################
resource "azurerm_resource_group" "rg" {
name = var.rg.name
location = var.rg.location
}

############################
# VIRTUAL NETWORK CREATION #
############################
resource "azurerm_virtual_network" "vnet" {
name = var.vnet.name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
address_space = var.vnet.address_space
dns_servers = var.vnet.dns_servers

subnet {
name = var.vnet.subnet1_name
address_prefix = var.vnet.subnet1_address_prefix
}

subnet {
name = var.vnet.subnet2_name
address_prefix = var.vnet.subnet2_address_prefix
}

subnet {
name = var.vnet.subnet3_name
address_prefix = var.vnet.subnet3_address_prefix
}

subnet {
name = var.vnet.subnet4_name
address_prefix = var.vnet.subnet4_address_prefix
}

subnet {
name = var.vnet.subnet5_name
address_prefix = var.vnet.subnet5_address_prefix
}
}

########################
# ROUTE TABLE CREATION #
########################
resource "azurerm_route_table" "fslogix_rt" {
name = var.rt.fslogix.name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
disable_bgp_route_propagation = false
}

resource "azurerm_route_table" "back_office_rt" {
name = var.rt.back_office.name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
disable_bgp_route_propagation = false
}

resource "azurerm_route_table" "dev_dev_rt" {
name = var.rt.dev_dev.name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
disable_bgp_route_propagation = false
}

resource "azurerm_route_table" "dev_prod_rt" {
name = var.rt.dev_prod.name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
disable_bgp_route_propagation = false
}

resource "azurerm_route_table" "front_office_rt" {
name = var.rt.front_office.name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
disable_bgp_route_propagation = false
}

##################
# ROUTE CREATION #
##################
resource "azurerm_route" "fslogix_routes" {
for_each = var.fslogix_routes
name = each.value.name
resource_group_name = azurerm_resource_group.rg.name
route_table_name = azurerm_route_table.fslogix_rt.name
address_prefix = each.value.address_prefix
next_hop_type = each.value.next_hop_type
next_hop_in_ip_address = each.value.next_hop_in_ip_address
}

resource "azurerm_route" "back_office_routes" {
for_each = var.back_office_routes
name = each.value.name
resource_group_name = azurerm_resource_group.rg.name
route_table_name = azurerm_route_table.back_office_rt.name
address_prefix = each.value.address_prefix
next_hop_type = each.value.next_hop_type
next_hop_in_ip_address = each.value.next_hop_in_ip_address
}

resource "azurerm_route" "dev_dev_routes" {
for_each = var.developer_dev_routes
name = each.value.name
resource_group_name = azurerm_resource_group.rg.name
route_table_name = azurerm_route_table.dev_dev_rt.name
address_prefix = each.value.address_prefix
next_hop_type = each.value.next_hop_type
next_hop_in_ip_address = each.value.next_hop_in_ip_address
}

resource "azurerm_route" "dev_prod_routes" {
for_each = var.developer_prod_routes
name = each.value.name
resource_group_name = azurerm_resource_group.rg.name
route_table_name = azurerm_route_table.dev_prod_rt.name
address_prefix = each.value.address_prefix
next_hop_type = each.value.next_hop_type
next_hop_in_ip_address = each.value.next_hop_in_ip_address
}

resource "azurerm_route" "front_office_routes" {
for_each = var.front_office_routes
name = each.value.name
resource_group_name = azurerm_resource_group.rg.name
route_table_name = azurerm_route_table.front_office_rt.name
address_prefix = each.value.address_prefix
next_hop_type = each.value.next_hop_type
next_hop_in_ip_address = each.value.next_hop_in_ip_address
}

###########################
# ROUTE TABLE ASSOICATION #
###########################
resource "azurerm_subnet_route_table_association" "fslogix_rta" {
subnet_id = ???????????????????????????????????????
route_table_id = azurerm_route_table.fslogix_rt.id
}

最佳答案

您可以通过以下方式获取所有subnet_id:

azurerm_virtual_network.vnet.subnet.*.id

您可以通过以下方式获取第一个subnet_id:

azurerm_virtual_network.vnet.subnet.*.id[0]

第二个subnet_id:

azurerm_virtual_network.vnet.subnet.*.id[1]

然后继续...

希望这有帮助!

关于azure - 来自内联虚拟网络资源的子网 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73893502/

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