David Parsonson
David Parsonson

Reputation: 575

Application gateway routing rule not updating with powershell script

I'm using the following script to try and update a routing rule in my application gateway. It runs fine with no errors but seemingly doesnt actually do anything when i go and check the rule it remains the same as prior to running the script:

Write-Host "Logging in...";
Login-AzureRmAccount

Write-Host "Selecting Subscription";
Select-AzureRmSubscription -SubscriptionId "id"

Write-Host "Get application gateway, settings and pool";
$AppGw = Get-AzureRmApplicationGateway -Name "name" -ResourceGroupName "rg"
$Settings  = Get-AzureRmApplicationGatewayBackendHttpSettings -Name "MaintenanceHTTPSetting" -ApplicationGateway $AppGw
$BackendPool = Get-AzureRmApplicationGatewayBackendAddressPool -Name "maintenancePool" -ApplicationGateway $AppGw

Write-Host $Appgw
Write-Host "Configure gateway rule";
Set-AzureRmApplicationGatewayRequestRoutingRule -ApplicationGateway $AppGw -Name "rule1" -RuleType Basic -BackendHttpSettings $Settings -BackendAddressPool $BackendPool

Any hints on where I may be going wrong here im not super familiar with powershell and its not giving me much information about whats happening.

Upvotes: 2

Views: 731

Answers (1)

David Parsonson
David Parsonson

Reputation: 575

The Set-AzureRmApplicationGatewayRequestRoutingRule cmdlet only modifies the routing rule in memory and does not commit this to the application gateway.

To address this the following code snippet should be used in comparison to above:

Write-Host "Selecting Subscription";
Select-AzureRmSubscription -SubscriptionId "id"

Write-Host "Get application gateway, settings and pool";
$AppGw = Get-AzureRmApplicationGateway -Name "name" -ResourceGroupName "rg"
$Settings  = Get-AzureRmApplicationGatewayBackendHttpSettings -Name "MaintenanceHTTPSetting" -ApplicationGateway $AppGw
$BackendPool = Get-AzureRmApplicationGatewayBackendAddressPool -Name "maintenancePool" -ApplicationGateway $AppGw

Write-Host "Configure gateway rule";
$AppGw = Set-AzureRmApplicationGatewayRequestRoutingRule -ApplicationGateway $AppGw -Name "rule1" -RuleType Basic -BackendHttpSettings $Settings -BackendAddressPool $BackendPool
Write-Host $AppGw;
Set-AzureRmApplicationGateway -ApplicationGateway $AppGw

However when doing this another issue is encountered which has been raised but remains unsolved here: https://github.com/Azure/azure-powershell/issues/3800

Upvotes: 2

Related Questions