Connecting App Service to MySQL In order for the web app to talk to MySQL we need to either allow all traffic to MySQL or add the outbound IP's for the web app.We can manually add addresses into the MySQL under the Networking blade. The problem we run into with the App Service, is that we need to input at least 7 addresses. This can be annoying and inaccurate. It's fairly easy to automate this with Azure CLI. Create a shell script addip.sh similar to the one below. Change the resource groups, webapp name, and MySQL server name.

 #!/usr/bin/env bash
COUNTER=1
for ip in $(az webapp show --resource-group wordpress --name wpaas --query outboundIpAddresses --output tsv | sed "s/,/ /g");do

    echo adding ip $COUNTER $ip
    az mysql flexible-server firewall-rule create --resource-group WordPress --name db-wpp --rule-name outbound$COUNTER --start-ip-address $ip --end-ip-address $ip
    let COUNTER=COUNTER+1
    echo $ip added
done
  1. This runs a query that will return a comma separated string of IP addresses.
  2. We separate the IP's and pass it to a for loop that adds the firewall rule.
  3. We also use a counter to create to display the number of the IP. It also uses this count to create a unique name for the rule.