In this article, we are going to learn how to add IP Address restrictions with in the Azure App Service using ARM Templates.
Introduction
Azure App Service supports controlling (allow or deny) the access based on IP Addresses. It’s a best practice to use Infrastructure as Code to automate the process. In this article, we are going to learn how to implement the same using Azure Resource Manager Templates.
Prerequisites
- Install Visual Studio Code
- Azure Resource Manager (ARM) Tools – An extension for Visual Studio Code for authoring ARM Templates
- Create Azure App Service Plan and App Service
Add IP Restrictions to App Service using ARM Templates
Azure App Service supports whitelisting the IP Addresses in the Networking blade as shown below

You can add the IP Address manually using the Networking blade above. However, we will use ARM Template for adding the IP Addresses.
Let’s navigate to Visual Studio Code, add a new resource by providing the type as sites and press CTRL + SPACE to bring up the auto-complete and select the Microsoft.Web/sites/config namespace as shown below.

The next important step is to provide the name of the resource. As shown below the name of this config resource must be prefixed by it’s parent, in our case, the Azure App Service name is azdevops-dev-eus-wapp-ip1

Once you provide the name, the next step is to configure the properties that includes the IP Address configurations as shown below.
"properties": {
"ipSecurityRestrictions": [
{
"ipAddress": "2.2.2.2/32",
"action": "Allow",
"tag": "Default",
"priority": 111,
"name": "IP1"
},
{
"ipAddress": "2.2.2.3/32",
"action": "Deny",
"priority": 112,
"name": "Deny IP2"
}
]
}
Once everything is ready, execute the ARM Template either by using Azure CLI or PowerShell. After successfully executing the ARM Template, you can view the IP Address configuring in the Azure App Service’s Networking blade as shown below.

That’s how Visual Studio Code with Azure Resource Manager (ARM) Tools extension allows us to quickly configure the IP Address configurations.
Below is the complete ARM Template for adding App Service Plan, App Service along with the Configurations.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {},
"functions": [],
"variables": {},
"resources": [
{
"name": "azdevops-dev-eus-asp1",
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2020-12-01",
"location": "[resourceGroup().location]",
"sku": {
"name": "F1",
"capacity": 1
},
"tags": {
"displayName": "azdevops-dev-eus-asp1"
},
"properties": {
"name": "azdevops-dev-eus-asp1"
}
},
{
"name": "azdevops-dev-eus-wapp-ip1",
"type": "Microsoft.Web/sites",
"apiVersion": "2020-12-01",
"location": "[resourceGroup().location]",
"tags": {
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/azdevops-dev-eus-asp1')]": "Resource",
"displayName": "azdevops-dev-eus-wapp-ip1"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', 'azdevops-dev-eus-asp1')]"
],
"properties": {
"name": "azdevops-dev-eus-wapp-ip1",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', 'azdevops-dev-eus-asp1')]",
}
},
{
"type": "Microsoft.Web/sites/config",
"apiVersion": "2022-03-01",
"name": "azdevops-dev-eus-wapp-ip1/web",
"location": "East US",
"properties": {
"ipSecurityRestrictions": [
{
"ipAddress": "2.2.2.2/32",
"action": "Allow",
"tag": "Default",
"priority": 111,
"name": "IP1"
},
{
"ipAddress": "2.2.2.3/32",
"action": "Deny",
"priority": 112,
"name": "Deny IP2"
}
]
}
}
],
"outputs": {}
}
Summary
In this article, we have learnt how to add IP Address restrictions with in the Azure App Service using ARM Templates using Visual Studio and the Azure Resource Manager (ARM) Tools extension.
Do you like this article? If you want to get more updates about these kind of articles, you can join my Learning Groups