gpt4 book ai didi

azure - 对每个地形创建的特定对象的引用

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

我为每个子网创建了两个子网。但是当我想将 nsg 与仅一个特定子网关联时,我不知道如何引用它(((谢谢

resource "azurerm_subnet" "subnets" {
for_each = {
def-subnet = var.subnet_address_prefixes[0]
GatewaySubnet = var.subnet_address_prefixes[1]
}
address_prefixes = each.value
name = each.key
virtual_network_name = azurerm_virtual_network.testvm-VNET.name
resource_group_name = azurerm_resource_group.testvm-RG.name

}

resource "azurerm_network_security_group" "def-nsg" {
location = var.region
name = "def-nsg"
resource_group_name = azurerm_resource_group.testvm-RG.name
security_rule {
access = "Allow"
direction = "Inbound"
name = "rdp"
priority = 300
protocol = "Tcp"
destination_port_range = "3389"
source_port_range = "3389"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}

resource "azurerm_subnet_network_security_group_association" "def-subnet-nsg-association" {
network_security_group_id = azurerm_network_security_group.def-nsg.id
subnet_id = here I want to use only def-subnet id

}

最佳答案

由于您使用了 for_each,因此您可以使用键引用 azurerm_subnet 的各个实例,例如 def-subnet:

subnet_id = azurerm_subnet.subnets["def-subnet"].id

关于azure - 对每个地形创建的特定对象的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73603151/

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