Thursday, May 26, 2016

Provisioning Virtual Directories using ARM Template in Azure

This is as much a means to record what to do as to post a blog, but I recently ran into a requirement to deploy web packages to an Azure Web App using MSDeploy where the packages were to be uploaded to virtual directories/applications. The web app was being deployed using Azure Resource Manager (ARM) and I was struggling to find the correct syntax on how to define these directories.

After some searching I found this answer from David Ebbo with a PowerShell way of doing the same thing and wandered if I might modify this to work inside an ARM template.

https://social.msdn.microsoft.com/Forums/azure/en-US/990f41fd-f8b6-43a0-b942-cef0308120b2/add-virtual-application-and-directory-to-an-azure-website-using-powershell?forum=windowsazurewebsitespreview#0435503d-032e-429d-93ff-e106be04f556

It turns out that you can and the answer is quite straight forward. Rather than using the PowerShell structure, define your 'props' as JSON instead and since this is deploying a resource type of 'Microsoft.Web/sites/config' the whole configuration struct can be placed inside your website section as follows:

{
"type": "Microsoft.Web/sites",
"name": "[variables('requestSiteName')]",
"apiVersion": "2015-08-01",
"location": "West Europe",
...
"properties": {
"name": "[variables('requestSiteName')]",
...
},
"dependsOn": [
...
],
"resources": [
{
...
},
{
"apiVersion": "2015-08-01",
"name": "web",
"type": "config",
"properties": {
"virtualApplications": [
{
"virtualPath": "/",
"physicalPath": "site\\wwwroot"
},
{
"virtualPath": "/foo",
"physicalPath": "site\\bar"
}
]
}
}
]
}