Skip to content

Instantly share code, notes, and snippets.

@alwalker
Created October 2, 2020 15:23
Show Gist options
  • Save alwalker/e1c0f7e79d64220f3556f426970a1664 to your computer and use it in GitHub Desktop.
Save alwalker/e1c0f7e79d64220f3556f426970a1664 to your computer and use it in GitHub Desktop.
One liner for adding your current IP to a Azure SQL Server firewall. Used in ADO.
MYIP=$(curl -s http://ipinfo.io/json | jq -r '.ip') && \
MATCH="^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$" && \
if [[ $MYIP =~ $MATCH ]]; then \
echo "Adding $MYIP to $(SERVER_NAME) firewall"; \
az sql server firewall-rule create -g $(RESOURCE_GROUP) -s $(SERVER_NAME) -n ALLOW_ADO --start-ip-address $MYIP --end-ip-address $MYIP; \
else \
echo "$MYIP is not a valid IP address."; \
exit 1; \
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment