[英]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.