[英]Terraform Output multiple subnet ids
I'm pretty new to terraform and I'm trying to learn and write a TF code to automate Azure VM deployment.我是 terraform 的新手,我正在尝试学习和编写 TF 代码以自动执行 Azure VM 部署。 I'm trying to cover each parts as modules (except rg) rather than keeping it in a single main.tf file.
我试图将每个部分都作为模块(rg 除外)进行覆盖,而不是将其保存在单个 main.tf 文件中。
I'm creating a single .net with 3 su.nets inside.我正在创建一个 .net,里面有 3 个 su.net。 Please find my code for the su.net module.
请找到我的 su.net 模块代码。 Please help me with below two points.
请帮我解决以下两点。
Su.net.tf苏网tf
resource "azurerm_subnet" "SUBNETS" {
for_each=var.Subnetlist
name=each.value.name
address_prefixes=[each.value.address]
resource_group_name = var.resource_group_name
virtual_network_name = var.virtual_network_name
}
NIC.tf网卡.tf
resource "azurerm_network_interface" "NETWORKINTERFACE" {
for_each=var.niclist
name = each.value.name
location = var.location
resource_group_name = var.resource_group_name
ip_configuration {
name = "ipconfig1"
subnet_id =
private_ip_address_allocation = "Dynamic"
}
}
azurerm_su.net.SU.NETS
is a map due to the use of for_each
:for_each
,您的azurerm_su.net.SU.NETS
是 map:output "subnet_ids" {
value = values(azurerm_subnet.SUBNETS)[*].id
}
module "myothermodule" {
source = "./modulepath"
subnets_ids = module.mysubnetmodule.subnet_ids
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.