I'm creating 4 vms through count in azurerm_virtual_machine but i want to create only one public IP and associate it with the first VM ? is that possible if so how ?
below is my template file
resource "azurerm_network_interface" "nics" {
count = 4
name = ...
location = ...
resource_group_name = ...
ip_configuration {
subnet_id = ...
private_ip_address_allocation = "Static"
private_ip_address = ...
}
}
resource "azurerm_public_ip" "public_ip" {
name = ...
location = ...
resource_group_name = ...
}
resource "azurerm_virtual_machine" "vms" {
count = 4
network_interface_ids = [element(azurerm_network_interface.nics.*.id, count.index)]
}
i have already gone through below questions but they are create multiple public ip's & add them to all vms.
question from:https://stackoverflow.com/questions/65935259/terraform-add-public-ip-to-only-one-azure-vm