I have an Azure Devops release pipeline in place for deploying files to a webapp.
At the beginning of this process, the current IP addresses are stored in a variable ($ipJson in script below). I then remove all existing IP addresses and add the build agent ip.
After my files are deployed, I need to restore the original IP addresses. The script I'm using works, but is slow and takes over 10 minutes to complete. The number of IP's are between 30-50.
How can I increase the speed of this process?
- Should I change anything to the script?
- Should I be doing it in a different way?
Right now it adds each IP address separately. Can't figure out how to do it in bulk - doesn't seem possible with CLI.
$jsonStr= @"
$(ipJson)
"@
$ipObj = $jsonStr | ConvertFrom-Json
foreach($rule in $ipObj.ipSecurityRestrictions){
if($rule.name -ne "Deny all" -and $rule.name -ne "Allow all" -and $rule.priority -ne 2147483647){
$params = "-g", "$(ResourceGroupName)",
"-n", "$(WebAppName)"
if(-not [string]::IsNullOrWhiteSpace($rule.priority)){
$params += "--priority", "$($rule.priority)"
}
if(-not [string]::IsNullOrWhiteSpace($rule.ip_address)){
$params += "--ip-address", "$($rule.ip_address)"
}
if(-not [string]::IsNullOrWhiteSpace($rule.action)){
$params += "--action", "$($rule.action)"
}
if(-not [string]::IsNullOrWhiteSpace($rule.description)){
$params += "--description", "$($rule.description)"
}
if(-not [string]::IsNullOrWhiteSpace($rule.name)){
$params += "--rule-name", "$($rule.name)"
}
if(-not [string]::IsNullOrWhiteSpace($rule.vnet_subnet_resource_id)){
$params += "--vnet-name", "$($rule.vnet_subnet_resource_id)"
}
if(-not [string]::IsNullOrWhiteSpace($rule.subnet_mask)){
$params += "--subnet", "$($rule.subnet_mask)"
}
Write-Host "Adding IP rule $($rule.ip_address) with params $params"
az webapp config access-restriction add @params
}
}