0
votes

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))}"

output values of subnets:

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

nic.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!
1
What do you hope to achieve with the following incorrect statement element(var.subnetwork-subnetid.*.id, (0,1))?Marcin
yes I know the above statement will not work but looking alterative function which help me to get multiple values of subnet element(var.subnetwork-subnetid.*.id, count.index) getting all the values but i need only two values from hereHaridvpsk

1 Answers

0
votes

Second argument in element is index:

index finds the index for a particular element value.

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:

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