Skip to content

Instantly share code, notes, and snippets.

@christopheranderson
Created February 10, 2017 08:54
Show Gist options
  • Save christopheranderson/ec6ab6b1eae152fca5321f4044b33d1d to your computer and use it in GitHub Desktop.
Save christopheranderson/ec6ab6b1eae152fca5321f4044b33d1d to your computer and use it in GitHub Desktop.
Function App ARM template with MSDeploy
{
"$schema": "http://schemas.management.azure.com/schemas/2015-01-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appName": {
"type": "string",
"metadata": {
"description": "The name of the function app that you wish to create."
}
},
"storageAccountType": {
"type": "string",
"defaultValue": "Standard_LRS",
"allowedValues": [
"Standard_LRS",
"Standard_GRS",
"Standard_ZRS",
"Premium_LRS"
],
"metadata": {
"description": "Storage Account type"
}
},
"_artifactsLocation": {
"type": "string"
},
"_artifactsLocationSasToken": {
"type": "securestring"
},
"SampleFunctionAppPackageFolder": {
"type": "string",
"minLength": 1,
"defaultValue": "SampleFunctionApp",
"metadata": {
"description": "WebDeploy package location. This path is relative to the _artifactsLocation parameter"
}
},
"SampleFunctionAppPackageFileName": {
"type": "string",
"minLength": 1,
"defaultValue": "package.zip",
"metadata": {
"description": "Name of the webdeploy package"
}
}
},
"variables": {
"functionAppName": "[parameters('appName')]",
"hostingPlanName": "[parameters('appName')]",
"storageAccountName": "[concat(uniquestring(resourceGroup().id), 'azfunctions')]"
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"name": "[variables('storageAccountName')]",
"apiVersion": "2015-06-15",
"location": "[resourceGroup().location]",
"properties": {
"accountType": "[parameters('storageAccountType')]"
},
"tags": {
"displayName": "Azure Functions Storage Account"
}
},
{
"type": "Microsoft.Web/serverfarms",
"apiVersion": "2015-04-01",
"name": "[variables('hostingPlanName')]",
"location": "[resourceGroup().location]",
"properties": {
"name": "[variables('hostingPlanName')]",
"computeMode": "Dynamic",
"sku": "Dynamic"
},
"tags": {
"displayName": "Consumption Plan"
}
},
{
"apiVersion": "2015-08-01",
"type": "Microsoft.Web/sites",
"name": "[variables('functionAppName')]",
"tags": {
"displayName": "SampleFunctionApp"
},
"location": "[resourceGroup().location]",
"kind": "functionapp",
"properties": {
"name": "[variables('functionAppName')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]"
},
"dependsOn": [
"[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
],
"resources": [
{
"apiVersion": "2016-03-01",
"name": "appsettings",
"type": "config",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('functionAppName'))]",
"[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
],
"properties": {
"AzureWebJobsStorage": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2015-05-01-preview').key1,';')]",
"AzureWebJobsDashboard": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('storageAccountName'),';AccountKey=',listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2015-05-01-preview').key1,';')]",
"FUNCTIONS_EXTENSION_VERSION": "latest",
"command": "deploy.cmd"
}
},
{
"name": "MSDeploy",
"type": "extensions",
"location": "[resourceGroup().location]",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('functionAppName'))]"
],
"tags": {
"displayName": "SampleFunctionAppPackage"
},
"properties": {
"packageUri": "[concat(parameters('_artifactsLocation'), '/', parameters('SampleFunctionAppPackageFolder'), '/', parameters('SampleFunctionAppPackageFileName'), parameters('_artifactsLocationSasToken'))]",
"dbType": "None",
"connectionString": "",
"setParameters": {
"IIS Web Application Name": "[variables('functionAppName')]"
}
}
}
]
}
]
}
@ealsur
Copy link

ealsur commented Dec 21, 2017

Thanks for this sample, it came pretty useful. One note though, the MSDeploy step can sometimes face a race condition with the config change due to this.

Adding "[concat('Microsoft.Web/sites/', variables('functionAppName'), '/Extensions/MSDeploy')]", to the dependsOn on appSettings seemed to solve it.

@jayasuryajeyakodi
Copy link

Having the config change depend on MSDeploy actually erases the function app code for me :\

@surajbnaik90
Copy link

surajbnaik90 commented Aug 23, 2018

We can avoid race condition by making appSettings to depend on MSDeploy.
More info - https://blogs.msdn.microsoft.com/hosamshobak/2016/05/26/arm-template-msdeploy-race-condition-issue/

@awaemmanuel
Copy link

awaemmanuel commented Oct 14, 2020

@christopheranderson Do you know of an equivalent of MSDeploy for Linux App Services. I am trying to use packageUri to deploy a web app from a zip folder stored in blob. I have the SAS token.

@prgnanamprayen
Copy link

@christopheranderson Do you know of an equivalent of MSDeploy for Linux App Services. I am trying to use packageUri to deploy a web app from a zip folder stored in blob. I have the SAS token.

have you found the answer for this ?

@christopheranderson
Copy link
Author

christopheranderson commented Sep 1, 2021

@prgnanamprayen try reading this doc and see if that answers your question: https://docs.microsoft.com/en-us/azure/app-service/deploy-run-package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment