2

I have to allow subnets as networking restrictions in Azure Webapp. We have number of app services and each app service has individual subnets. My script should add all subnets into each app service. My issue is I don't know how to loop subnets so it will add all of them into each app service. Shall somehow increment it or create another nested loop.

$apps = @('trustledger','librarian','statements-document','statement-docmosis','statements-reporting','publicapi', 'payment-consumer', 'address', 'rules','worker','common','caouser','comms','mailroom','docgen-browserless','payment','graphqldocuments','workflow','graphql','property','user','property-consumer','docgen','docmosis','docgen-consumer','reporting','template-generator','document','statement')
$env = 'test'
$region = 'aue'
    
    
ForEach ($app in $apps) {
        
     az webapp config access-restriction add -g "kol-$($env)-$($region)-apps-rg" -n "kol-$($env)-$($region)-$($app)-net6-app" --rule-name "Allow_$($app)"  --action Allow --vnet-name "kol-$($env)-$($region)-vnet" --subnet "$($app)-subnet" --vnet-resource-group kol-$($env)-$($region)-network-rg --priority 300
        
 } 

1 Answer 1

2

No worries guys. All done. Found answer by myself. This is my solution:

# https://learn.microsoft.com/en-us/cli/azure/webapp/config/access-restriction?view=azure-cli-latest#az-webapp-config-access-restriction-add
$apps = @('trustledger','librarian','statements-document','statement-docmosis','statements-reporting','publicapi', 'payment-consumer', 'address', 'rules','worker','common','caouser','comms','mailroom','docgen-browserless','payment','graphqldocuments','workflow','graphql','property','user','property-consumer','docgen','docmosis','docgen-consumer','reporting','template-generator','document','statement')
$env = 'test' 
$region = 'aue' 


foreach ($app in $apps) {
  $filtered = $apps.where{$_ -notin  $app} #filering subnets, so app service does not add its own subnet as restriction rule
  foreach ($a in $filtered) {
    az webapp config access-restriction add -g "kol-$($env)-$($region)-apps-rg" -n kol-$($env)-$($region)-$($app)-net6-app --rule-name "Allow_$($a)"  --action Allow --vnet-name "kol-$($env)-$($region)-vnet" --subnet "$($a)-subnet" --vnet-resource-group kol-$($env)-$($region)-network-rg --priority 300
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.