Search code examples
azureazure-web-app-serviceazure-virtual-networkazure-rm-template

ARM Template for to configure App Services with new VNet Integration feature?


I am working on ARM Templates, I have created the template file with two or more azure app services along with app service plan and then configured with VNET Integration of each app service.

This is sample JSON code:

    {
  "comments": "Web-App-01",
  "name": "[variables('app_name_01')]",
  "type": "Microsoft.Web/sites",
  "location": "[variables('location')]",
  "apiVersion": "2016-08-01",
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', variables('asp_name_01'))]"
  ],
  "tags": {
    "displayName": "[variables('app_name_01')]"
  },
  "properties": {
    "name": "[variables('app_name_01')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('asp_name_01'))]",
    "siteConfig": {
      "alwaysOn": true
    }
  },
    "resources": [
      {
        "type": "Microsoft.Web/sites/virtualNetworkConnections",
        "name": "[concat(variables('app_name_01'), '/', variables('vnet_connection_name'),uniqueString('asdsdaxsdsd'))]",
        "apiVersion": "2016-08-01",
        "location": "[variables('location')]",
        "properties": {
          "vnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vm_vnet_name'), variables('web_subnet_name'))]"
        },
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('app_name_01'))]",
          "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vm_vnet_name'), variables('web_subnet_name'))]"
        ]
      }
    ]
},
{
  "comments": "Web-App-02",
  "name": "[variables('app_name_02')]",
  "type": "Microsoft.Web/sites",
  "location": "[variables('location')]",
  "apiVersion": "2016-08-01",
  "dependsOn": [
    "[resourceId('Microsoft.Web/serverfarms', variables('asp_name_02'))]"
  ],
  "tags": {
    "displayName": "[variables('app_name_02')]"
  },
  "properties": {
    "name": "[variables('app_name_02')]",
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('asp_name_01'))]",
    "siteConfig": {
      "alwaysOn": true
    }
  },
    "resources": [
      {
        "type": "Microsoft.Web/sites/virtualNetworkConnections",
        "name": "[concat(variables('app_name_02'), '/', variables('vnet_connection_name'),uniqueString('asdsdaxsdsd'))]",
        "apiVersion": "2016-08-01",
        "location": "[variables('location')]",
        "properties": {
          "vnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vm_vnet_name'), variables('web_subnet_name'))]"
        },
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('app_name_02'))]",
          "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vm_vnet_name'), variables('web_subnet_name'))]"
        ]
      }
    ]
}

The above code works fine for few azure app services, but for the rest of the app services I am getting internal server error or Conflict or Bad Request during VNET Integration of Azure App Service.

Note: When I deployed the above the JSON Code, the old VNET integration is configured instead of New VNET (Preview) feature. So, I need to configure New VNET (Preview) feature for each app service.

So, can anyone suggest me how to resolve the above issue.


Solution

  • I've found a working example for this on an Azure Docs GitHub post:

    How do we integrate the new vnet integrartion with ARM templates?

    Seems to work a different way with the new VNet integration which uses a Microsoft.Web/sites/config sub-resource named virtualNetwork instead of the Microsoft.Web/sites/virtualNetworkConnections sub-resource

    As well as a few requirements that need to be set on the target subnet / vnet (described in the link). The integration piece looks something like this:

       {
          "apiVersion": "2018-02-01",
          "type": "Microsoft.Web/sites",
          "name": "[parameters('appName')]",
          "location": "[resourceGroup().location]",
    
    ...
    
          "resources": [
            {
              "name": "virtualNetwork",
              "type": "config",
              "apiVersion": "2018-02-01",
              "location": "[resourceGroup().location]",
              "properties": {
                "subnetResourceid": "[parameters('subnetResourceId')]",
                "swiftSupported": true
              },
              "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('appName'))]"
              ]
            }
          ]
       },
    

    Apart from this I've not found much else documented, except for a reference to it in the azure-rest-api-specs which has the "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/networkConfig/virtualNetwork" endpoint defined:

    azure-rest-api-specs / WebApps.json

    It also seems (as the spec suggests) replacing "type": "config" with "type": "networkConfig" also works.