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?
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.
My default Pool in the rule is loadbalancerbackendpool
as you can see below:
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.
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