简体   繁体   English

我创建了 4 个子网并创建了 output 值以在一个变量中获取所有子网 id。那么我如何计划检索 2 个值以附加 nics

[英]I have created 4 subnets and created output values to get all subnets ids in one variable .So how can I plan to retrieve 2 values to attach the nics

Error: Unbalanced parentheses错误:括号不平衡

on.terraform\modules\nics\main.tf line 19, in resource "azurerm_network_interface" "NIC1": 19: subnet_id = "${element(var.subnetwork-subnetid.*.id, (0,1))}" on.terraform\modules\nics\main.tf 第 19 行,在资源“azurerm_network_interface”“NIC1”中:19:subnet_id = “${element(var.subnetwork-subnetid.*.id, (0,1))}”

output values of subnets:子网的 output 值:

output "subnetwork-subnetid" {
  value = concat(azurerm_subnet.subnetwork.*.id, azurerm_subnet.subnetwork6.*.id)
}

nic.tf网卡.tf

resource "azurerm_network_interface" "NIC1" {
  #count = "${length(var.subnetwork-subnetid)}"
  #for_each= toset(var.subipv4)
  count = "${length(var.subipv4)}"
  name  = "${lookup(element(var.subipv4, count.index), "name")}"
  #name                = var.nic-name
  location                      = var.rg-location
  resource_group_name           = var.rg-name
  enable_ip_forwarding          = true
  enable_accelerated_networking = true
  ip_configuration {
    name                          = "ipconfig"
    subnet_id                     = "${element(var.subnetwork-subnetid.*.id, (0,1))}"
    private_ip_address_allocation = "Dynamic"
    #public_ip_address_id          = azurerm_public_ip.pubip.id
    #public_ip_address_id = azurerm_public_ip.pubip.*.id
    primary = true
  }
  tags = {
    name = "${lookup(element(var.subipv4, count.index), "name")}"
  }
}```

Please someone help me in this issue.Thanks!

Second argument in element is index : element中的第二个参数是index

index finds the index for a particular element value. index 查找特定元素值的索引。

Thus to get few elements from the list based on indices, you can do:因此,要根据索引从列表中获取少量元素,您可以执行以下操作:

subnet_id = [ for idx in [0, 1]: element(var.subnetwork-subnetid.*.id, idx) ]

If you want a range of indies, you can use slice :如果你想要一系列独立,你可以使用slice

subnet_id = slice(var.subnetwork-subnetid.*.id, 0, 2)

暂无
暂无

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

相关问题 Output 来自使用 for_each 循环创建的多个子网的值 - Output of values from multiple subnets created using a for_each loop 如何使用 Bicep 在现有 .net 上创建 su.net 数组? - How can I create an array of subnets on an existing vnet using Bicep? 如何将新创建的子网引用到 terraforn azure 中的另一个模块 - How to refer newly created subnets to another modules in terraforn azure 我可以将 2 个 NIC 附加到 VM,但计划使用 terraform azure 将总共 4 个 NIC 添加到 linux VM - I could able to attach 2 NICS to the VM but Plan to add total 4 NICs to the linux VM using terraform azure 获取\列出所有 azure su.nets - Get\List all azure subnets 我从具有两个 NIC 的 VM 创建了一个 Azure 映像。 当我使用映像创建新 VM 时,我只能在新 VM 中看到一个 NIC - I have created an Azure image out of a VM which has two NICs. when I created a new VM using image I am was able to see only one NIC in new VM 如何在 Bicep 中定义子网,以便父 Vnet 具有引用并且我可以依赖子网部署? - How do I defined subnets in Bicep such that the parent Vnet has a reference and that I can dependOn the subnet deployment? 使用 Powershell Az 命令时未创建子网 - Subnets are not getting created while using Powershell Az commands Azure 内部负载均衡器能否拥有属于 VNET 中不同子网的后端? - Can Azure Internal Loadbalancer have backends belonging to different subnets in the VNET? 如何将专用端点附加到使用 ARM 模板创建的逻辑应用程序 - How can I attach Private End Point to Logic App created using ARM Template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM