Finding out IPs of Azure function
Introduction
The IP address of an Azure function can be very useful, especially if you are using IP based network restrictions or any kind of firewall to block requests from unknown IPs. Azure gives us a single inbound IP address to the function, but a range of possible outbound ones. This is so that Azure can do its internal load balancing. The issue you might hit is that these IPs can all change.
When can IP change
There are specific cases when IPs can change. Again these are listed in the documentation. Both the inbound and outbound IP addresses can change. So how do we figure out, on the fly, what are the IPs of our Azure function?
Resource graph
This is when Azure Resource Graph becomes super useful. The resource graph is a powerful management tool to query, explore and analyse your cloud resources at scale. We can see all resources, their properties etc using Kusto query language (KQL) queries.
Using resource graph
Steps to finding out the IPs of our function are as follows. Note that we have a function app named blog-test-funap
.
- Go to
Azure Resource Graph Explorer
on your Azure portal -
Enter query
Resources | where name =~ 'blog-test-funap' and type =~ 'microsoft.web/sites'
Notice the =~
which means, do a case insensitive comparison. And we filter the resources down to microsoft.web/sites
, which is what function apps are under the hood.
Note that there are multiple JSON properties to get full list of IP addresses such as possibleOutboundIpAddresses
, possibleInboundIpAddresses
and outboundIpAddresses
.
Conclusion
Azure resource graph gives a lot of power at your fingertips. This post was a demonstration at Azure portal, but we can do the same using AZ CLI, Azure Powershell or dotnet sdk or REST API. Thereby having full knowledge of our Azure resources with automation.
Hope this was useful. Please do share your learnings. If you have any thoughts or comments please do get in touch with me on twitter @rubberduckdev. Or use the Disqus plugin below.