简体   繁体   English

Terraform Output 多个 su.net id

[英]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"
  }
}
  1. How can I output the su.net_ids (of three created su.nets).我怎样才能 output su.net_ids(三个创建的 su.nets)。
  2. How can I pass these su.net_ids to another module (say for creating Network interface)我如何将这些 su.net_ids 传递给另一个模块(比如创建网络接口)
  1. Since your 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
}
  1. You pass it as any other variable:您将它作为任何其他变量传递:
module "myothermodule" { 
  source = "./modulepath"
  subnets_ids = module.mysubnetmodule.subnet_ids
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM