gpt4 book ai didi

azure - 如果我不想为 terraform 中的所有对象 map 提供值

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

  • 如果我不想为虚拟中的所有子网提供路由表网络那么我应该在这里使用什么,因为如果我没有路线运行表然后我收到错误。在subnet2 中需要路由表id。
│ Missing required argument

│ with module.virtual_network["test-vnet"].azurerm_subnet_route_table_association.route-link-subnet["subnet2"],
│ on modules\virtualNetwork\main.tf line 30, in resource "azurerm_subnet_route_table_association" "route-link-subnet":
│ 30: route_table_id = each.value.route_table

│ The argument "route_table_id" is required, but no definition was found.

我在这里创建多个虚拟网络,每个虚拟网上有多个子网。

variable "networks" {
type = map(object({
resource_group_name = string
location = string
addressSpace = list(string)
dnsServers = optional(list(string))
subnets = map(object({
addressPrefix = string
privateEndpointNetworkPolicies = optional(bool)
privateLinkServiceNetworkPolicies = optional(bool)
service_endpoints = optional(list(string))
route_table = optional(string)
}))
}))
}

networks = {
test-vnet = {
resource_group_name = "testrg"
location = "eastus"
addressSpace = ["10.229.192.0/20"]
dnsServers = ["10.231.18.4"]
subnets = {
subnet1 = {
addressPrefix = "10.229.199.0/24"
networkSecurityGroups = {
subnet1-nsg = {
security_rules = []
}
}
route_table = "/subscriptions//resourceGroups/test-rg/providers/Microsoft.Network/routeTables/test-rt"
}
subnet2 = {
addressPrefix = "10.229.198.0/24"
privateEndpointNetworkPolicies = true
privateLinkServiceNetworkPolicies = true
service_endpoints = [
"Microsoft.Storage"
]
networkSecurityGroups = {
subnet2-nsg = {
security_rules = []
}
}
}
}
}

resource "azurerm_subnet_route_table_association" "route-link-subnet" {
for_each = var.subnets
subnet_id = module.subnets[each.key].subnet_id
route_table_id = each.value.route_table
depends_on = [
module.subnets,
azurerm_virtual_network.Virtual_Network
]
}

最佳答案

您必须在 var.subnets 中为 subnet2 提供 route_table

关于azure - 如果我不想为 terraform 中的所有对象 map 提供值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76259960/

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