1

I am trying to change the backend address pool on a pre-existing Load Balancer rule.

I have looked into using Set-AzLoadBalancerRuleConfig but it would appear I need to provide all the information for the rule to be rebuilt... ie: the FrontendIpConfiguration, Protocol, FrontendPort, BackendPort, and Probe, as well at the new BackendAddressPool to be used:

ForEach($Rule in $BAPFrom.LoadBalancingRules){

$LbRule = $slb.LoadBalancingRules | Where-Object {$_.Id -eq $Rule.Id}

$slb | Set-AzLoadBalancerRuleConfig -Name $LbRule.Name `
            -FrontendIPConfiguration $slb.FrontendIpConfigurations[0] `
            -Protocol $LbRule.Protocol `
            -FrontendPort $LbRule.FrontendPort `
            -BackendPort $LbRule.BackendPort `
            -BackendAddressPool $BAP #`
            #-Probe $LbRule.Probe}

Is there not a way to just change the BackendAddressPool on a pre-existing rule, without needing to pass in each of these parameters again?

Jeffrey
  • 2,095
  • 3
  • 20
  • 36
  • May I know if you have tried `Set-AzLoadBalancerBackendAddressPool`.Please refer this for more details : [Set-AzLoadBalancerBackendAddressPool (Az.Network) | Microsoft Docs](https://learn.microsoft.com/en-us/powershell/module/az.network/set-azloadbalancerbackendaddresspool?view=azps-6.6.0) – Ansuman Bal Nov 09 '21 at 07:54
  • I don't believe this is suitable, as the second backend address pool already exists, I just need to switch a certain batch of rules over from the first backend address pool to the second. – Jeffrey Nov 09 '21 at 08:57
  • then i don't think that will be possible as updating the load balancer rule needs all the parameters. – Ansuman Bal Nov 09 '21 at 09:11
  • let me run some tests and confirm it for you .. – Ansuman Bal Nov 09 '21 at 09:11
  • Thanks. I guess essentially what I want to do is this: $slb = Get-AzLoadBalancer -Name "LB-1" -ResourceGroupName "LbTest"; $MyBackendPool2 = $slb | Get-AzLoadBalancerBackendAddressPool -Name 'pool-ext-b'; Get-AzLoadBalancerRuleConfig -LoadBalancer $slb -Name 'rule-int-6464' | Set-AzLoadBalancerRuleConfig -BackendAddressPool $MyBackendPool2; So that it just switches the existing rule to use a different existing backend pool, but like you say, it requires all of the parameters – Jeffrey Nov 09 '21 at 09:20

1 Answers1

1

As mentioned in the Comments , The process which you are trying to implement is not possible .

I tested the same in my environment:

Scenario: 1 load balancer , 1 load balancing rule and 2 backend pools.

enter image description here

My default Pool in the rule is loadbalancerbackendpool as you can see below:

enter image description here

I tried to change it to the second pool i.e. Loadbalancerbackenpooloutbound.It was successful but if you see the output only the backendpool id is correct and others have been changed to default and are not same as my previous rule as shown below.

enter image description here

Solution: The only solution available is that you get the rule config which you want to update and while updating the rule provide the parameters collected from the get rule operation, something like below:

$slb = Get-AzLoadBalancer -Name "ansumantest-lb" -ResourceGroupName "resourcegroup"
$MyBackendPool2 = $slb | Get-AzLoadBalancerBackendAddressPool -Name 'LoadBalancerBackEndPoolOutbound'
$rule=Get-AzLoadBalancerRuleConfig -LoadBalancer $slb -Name 'myHTTPRule'
$slb|Set-AzLoadBalancerRuleConfig -Name $rule.Name -BackendAddressPool $MyBackendPool2 -Protocol $rule.Protocol -FrontendPort $rule.FrontendPort -BackendPort $rule.BackendPort
Ansuman Bal
  • 9,705
  • 2
  • 10
  • 27