im trying to build a script that will build VMs based on count. i have managed to get most of it working, but the part im failing on is assigning the created public Ips to the Nic. the public ips are created but fail on the assignment, im not sure on how to parse correctly. Code and errors.
# Create public IPs
resource "azurerm_public_ip" "myterraformpublicip" {
count = 2
name = "myPublicIP-${count.index + 1}"
location = "westeurope"
resource_group_name = azurerm_resource_group.myterraformgroup.name
allocation_method = "Dynamic"
}
# Create network interface
resource "azurerm_network_interface" "myterraformnic" {
count = 2
name = "myNIC-${count.index + 1}"
location = "westeurope"
resource_group_name = azurerm_resource_group.myterraformgroup.name
ip_configuration {
name = "myNicConfiguration"
subnet_id = azurerm_subnet.myterraformsubnet.id
private_ip_address_allocation = "Dynamic"
public_ip_address_id = "azurerm_network_interface.myterraformpublicip.[count.index + 1].id"
}
}
#The error when running the plan.
Error: Can not parse "ip_configuration.0.public_ip_address_id" as a resource id: Cannot parse Azure ID: parse "element(azurerm_network_interface.myterraformpublicip.*.id, count.index + 1)": invalid URI for request



