我在vNet资源块中创建了一个包含3个子网的虚拟网络,我想知道如何获取子网的ID?我知道是否使用azurerm_subnet分别创建了这些子网,然后在输出中使用它们,但如果子网是与vnet内联创建的,我就不确定了。
主文件.tf
resource "azurerm_virtual_network" "vnet" {
name = var.vnet.name
resource_group_name = azurerm_resource_group.rg.id
location = azurerm_resource_group.rg.id
address_space = var.vnet.address_space
dns_servers = var.vnet.dns_servers
subnet {
name = var.subnet.key_vault.name
address_prefix = var.subnet.key_vault.address_prefix
}
subnet {
name = var.subnet.storage_account.name
address_prefix = var.subnet.storage_account.address_prefix
}
subnet {
name = var.subnet.hostpool1.name
address_prefix = var.subnet.hostpool1.address_prefix
}
}
输出.tf
output "subnet_id" {
value = azurerm_virtual_network.vnet.subnet[*].id
}
错误消息
│ Error: Incorrect attribute value type
│
│ on session_hosts/main.tf line 31, in resource "azurerm_network_interface" "avd_nic":
│ 31: subnet_id = var.subnet_id
│ ├────────────────
│ │ var.subnet_id is list of string with 3 elements
│
│ Inappropriate value for attribute "subnet_id": string required.
1条答案
按热度按时间unftdfkk1#
我尝试重现,以输出子网ID,并得到以下代码的输出:
变量.tf
main.tf
请尝试以下面的方式循环,并对内联子网进行少量更正。
value = values(azurerm_subnet.SUBNETS)[*].id
*一月一日