terraform - Accessing the output from module via index -
i trying create 2 vms on azure using terraform.
i create 2 nics like
variable "internalips" { description = "list of internal ips" default = ["10.0.2.10", "10.0.2.11"] type = "list" } resource "azurerm_network_interface" "helloterraformnic" { count = 2 name = "nic-${count.index}" location = "west us" resource_group_name = "myrg" ip_configuration { name = "testconfiguration1" subnet_id = "${azurerm_subnet.helloterraformsubnet.id}" private_ip_address_allocation = "static" private_ip_address = "${element(private_ip_address, count.index)}" } }
now want use them in module azurerm_virtual_machine
resource "azurerm_virtual_machine" "helloterraformvm" { count = 2 name = "${element(elasticmachines, count.index)}" location = "west us" resource_group_name = "myrg" network_interface_ids = "${element(azurerm_network_interface.helloterraformnic, count.index)}" .... }
this gives me error
failed load root config module: error loading azure/rg.tf: error reading config azurerm_virtual_machine[helloterraformvm]: azurerm_network_interface.helloterraformnic: resource variables must 3 parts: type.name.attr in:
${element(azurerm_network_interface.helloterraformnic, count.index)}
how can use above created nics using index ?
first thinking use length
function counts more hard coding it.
from
count = 2
change
count = "${length(var.internalips)}"
for problem, need tell resource attribute want value.
network_interface_ids = "${element(azurerm_network_interface.helloterraformnic.id, count.index)}"
refer:
Comments
Post a Comment