0

I have created availability set (3 Vm) using terraform. Created one load balancer and trying to add internal IPs in load balancer pool, but doing something wrong so it creates 3 load balancer backend pool and add all VM internal ip in it. How can I create one load balancer backend pool and associated created ip of VM's to it.

Current Code :

resource "azurerm_network_interface_backend_address_pool_association" "tf" {
    count = 3
    network_interface_id = "${element(azurerm_network_interface.tf-nic.*.id, count.index)}"
    ip_configuration_name = "app-vm-${count.index}-nic"
    backend_address_pool_id = azurerm_lb_backend_address_pool.tf.id
    
}

I tried this code also, but it it won't work in my case

resource "azurerm_lb_backend_address_pool_address" "tf" {
  name                    = "lb-bepool-address-${var.resource_postfix}"
  backend_address_pool_id = azurerm_lb_backend_address_pool.tf.id
  virtual_network_id      = azurerm_virtual_network.tf.id
  #ip_address              = "${element(azurerm_virtual_machine.tf.*.private_ip_address, count.index)}"
  #ip_address              = "${element(azurerm_network_interface.tf-nic.*.private_ip_address, count.index)}"
  
}
vikrantx
  • 593
  • 5
  • 22
  • Have you tried with this code : https://learn.microsoft.com/en-us/azure/developer/terraform/create-vm-cluster-with-infrastructure? – RahulKumarShaw Jun 20 '22 at 07:08
  • Also check out this : https://stackoverflow.com/questions/68326873/how-to-add-a-backend-with-virtual-machine-ip-for-azure-load-balancer-in-terrafor?rq=1 – RahulKumarShaw Jun 20 '22 at 07:13

0 Answers0