Created
January 21, 2022 10:54
-
-
Save PatrickKalkman/5550afb949619f5d72135d6327ea8d74 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Add-AccessRestrictionToAppService([string] $ResourceGroupName, [string] $Name, [string] $IpFilterRuleName, [string] $IpAddress, [string] $Priority) | |
| { | |
| Write-Information "Adding rule $IpFilterRuleName to allow api management service with ip $IpAddress and $Priority access to $Name" | |
| Add-AzWebAppAccessRestrictionRule -ResourceGroupName $ResourceGroupName -WebAppName $Name -Name $IpFilterRuleName -Priority $Priority -Action Allow -IpAddress $IpAddress | |
| Update-AzWebAppAccessRestrictionConfig -Name $appService.Name -ResourceGroupName $ResourceGroupName -ScmSiteUseMainSiteRestrictionConfig | |
| # Also add the access restriction to the staging slots | |
| $allSlots = Get-AzWebAppSlot -ResourceGroupName $ResourceGroupName -Name $Name | |
| Foreach ($slot in $allSlots) | |
| { | |
| $slotName = Get-SlotName -SlotName $slot.Name -AppServiceName $Name | |
| Write-Information "Adding rule $IpFilterRuleName to allow api management service with ip $IpAddress and priority $Priority access to $Name slot $slotName" | |
| Add-AzWebAppAccessRestrictionRule -ResourceGroupName $ResourceGroupName -WebAppName $Name -Slot $slotName -Name $IpFilterRuleName -Priority $Priority -Action Allow -IpAddress $IpAddress | |
| Update-AzWebAppAccessRestrictionConfig -ResourceGroupName $ResourceGroupName -Name $Name -Slot $slotName -ScmSiteUseMainSiteRestrictionConfig | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment