Search code examples
azureazure-devopsazure-rm-templateazure-load-balancerazure-vm

Azure Load balancer - Add existing VMs to Azure Load Balancer with ARM template


I have two VMS backendvm0 and backendvm1, I am trying to add these Vms to the backendpool of Azure load balancer from Load balancer ARM template deployment. I am using parameter object as below. It is not giving any error, load balancer is being created with name tlba001backendpool_test but it is not showing any VM attached to it.

 "backendAddressPools": {
  "value": [
    {
      "name": "tlba001backendpool_test",
      "id": "",
      "properties": {
        "loadBalancerBackendAddresses": [
          {
            "name": "backendvm0",
            "properties": {
              "ipAddress": "10.0.2.5"
            }

          },
          {
            "name": "backendvm1",
            "properties": {
              "ipAddress": "10.0.2.4"
            }
          }
        ] 

      }
    }
  ]
},

enter image description here


Solution

  • Because this is being governed by the nic properties, not load balancer, you need to modify the NIC properties and assign the NIC to the load balancer.

    {
        "apiVersion": "2015-05-01-preview",
        "type": "Microsoft.Network/networkInterfaces",
        "name": "[concat(parameters('nicNamePrefix'), copyindex())]",
        "location": "[resourceGroup().location]",
        "copy": {
            "name": "nicLoop",
            "count": "[variables('numberOfInstances')]"
        },
        "dependsOn": [
            "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]",
            "[concat('Microsoft.Network/loadBalancers/', parameters('lbName'))]"
        ],
        "properties": {
            "ipConfigurations": [
                {
                    "name": "ipconfig1",
                    "properties": {
                        "privateIPAllocationMethod": "Dynamic",
                        "subnet": {
                            "id": "[variables('subnetRef')]"
                        },
                        "loadBalancerBackendAddressPools": [
                            {
                                "id": "[concat(variables('lbID'), '/backendAddressPools/BackendPool1')]"
                            }
                        ]
                    }
                }
            ]
        }
    }
    

    https://github.com/Azure/azure-quickstart-templates/blob/master/201-2-vms-loadbalancer-lbrules/azuredeploy.json