question

VikasTiwari-2263 avatar image
0 Votes"
VikasTiwari-2263 asked ·

Adding new rule in exisitng app gateway through powershall

Hi,

I have an existing app gateway has 4 path based rule setup. I need to add new entry in app gateway through powershell, I have used following commands but after running it removes all existing entries and adds only new rule (overrides all 4 rules and add only new entry):

$appgw = Set-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgw -Name "pathBasedRule" -PathRules $myPathRule -DefaultBackendAddressPool $backendPool -DefaultBackendHttpSettings $backendPoolSetting

Set-AzApplicationGateway -ApplicationGateway $appgw

I couldn't find any power shell command where I can fetch all 4 rules then I will add 1 new rule, so that
my app gateway will have 5 rules after running. how can I do that through PS?

Thnaks

azure-application-gatewayazure-automation
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VikasTiwari-2263 avatar image
0 Votes"
VikasTiwari-2263 answered ·

I have found the solution through ARM template. If anyone facing similar kind of issue here are the details:

As I didn't find any ps command to add new rule in existing path based rule, we can add completely new rule using Add-AzApplicationGatewayUrlPathMapConfig but I want to just add new path based condition. below is json template that has 2 rules:

     "urlPathMaps": [
       {
         "name": "urlPathMap1",
         "properties": {
           "defaultBackendAddressPool": {
             "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPoolDefault')]"
           },
           "defaultBackendHttpSettings": {
             "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
           },
           "pathRules": [
             {
               "name": "pathRule1",
               "properties": {
                 "paths": [
                   "[parameters('pathMatch1')]"
                 ],
                 "backendAddressPool": {
                   "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPool1')]"
                 },
                 "backendHttpSettings": {
                   "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
                 }
               }
             },
             {
               "name": "pathRule2",
               "properties": {
                 "paths": [
                   "[parameters('pathMatch2')]"
                 ],
                 "backendAddressPool": {
                   "id": "[concat(variables('applicationGatewayID'), '/backendAddressPools/appGatewayBackendPool2')]"
                 },
                 "backendHttpSettings": {
                   "id": "[concat(variables('applicationGatewayID'), '/backendHttpSettingsCollection/appGatewayBackendHttpSettings')]"
                 }
               }
             }
           ]
         }
       }
     ]

we can add another rule to add new path condition in existing app gateway, here is github link for complete sample template.

https://github.com/Azure/azure-quickstart-templates/blob/master/201-application-gateway-url-path-based-routing/azuredeploy.json

Hope this will help someone.

Thanks.

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

suvasara-MSFT avatar image
0 Votes"
suvasara-MSFT answered ·

Greetings,

You need to use "Add" instead of "Set" here in order to avoid overriding of previous rules. The Add-AzApplicationGatewayUrlPathMapConfig cmdlet adds an array of URL path mappings to a back end server pool. Here is an example script for your reference,

$appgw = Add-AzApplicationGatewayUrlPathMapConfig -ApplicationGateway $appgw -Name "APPGW-Name" -PathRules $pathRule - DefaultBackendAddressPool $pool -DefaultBackendHttpSettings $poolSettings

$appgw = Set-AzApplicationGateway -ApplicationGateway $appgw

This will allow you to add the new rules with out overriding the previous one.


Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.



· 1 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for your time.

What should be -name for Add-AzApplicationGatewayUrlPathMapConfig?

In my case I already have one path based rule named 'pathBasedRule' and in this rule I have multiple rules configured for different url requests.
When I try to give -Name 'pathBasedRule' under Add-AzApplicationGatewayUrlPathMapConfig, I received an error that its already exists.

All I want is to update exisitng path based rule and add another path based routing for new API.

Thanks

0 Votes 0 · ·