I have a powershell task that connects to an Azure database and executes SQL Scripts. The script works when executed on any machine for which the corresponding IP address or range has been set as allowable within the firewall rules in Azure.
The problem is when the Script is executed within a DevOps pipeline I always get the error,
"Invoke-Sqlcmd : Cannot open server 'SERVERNAME' requested by the login. Client with IP address 'XX.XXX.XXX.XXX' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect."
I understand what's happening but after setting a specified range of IP's based on the IP referenced during the error; on a subsequent execution the agent runs on yet another IP which is outside of the range I allow.
After a couple of times doing this it was obvious that I was simply widening the IP range beyond acceptable for reasons of security.
So the question is there a way to restrict/control the range of the DevOps run agents for tasks where they're required to access Azure based Resources that are under access control via firewalls?