13
votes

I've got an ARM template (included below) to deploy an Azure Function App. I deploy it with:

az group deployment create --resource-group my-group --template-file my-function-app.json

This works and I can then deploy my functions successfully using the VS Code plugin or Azure Functions Core Tools.

However, if I then re-deploy the ARM template (for example to update an application setting) then I lose my functions and need to re-deploy them again. Is this expected behaviour? It's not what I observe when deploying e.g. a Web App via an ARM template. Is there something specific I can do when deploying an ARM template for a Function App to preserve my deployed functions?

my-function-app.json:

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        ...
    },
    "variables": {
        ...
    },
    "resources": [
        {
            "apiVersion": "2015-08-01",
            "type": "Microsoft.Web/sites",
            "name": "[variables('collectorFunctionAppName')]",
            "location": "[parameters('location')]",
            "kind": "functionapp",
            "properties": {
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('hostingPlanName'))]",
                "siteConfig": {
                    "appSettings": [
                        {
                            ...
                        }
                    ]
                }
            }
        }
    ],
    "outputs": {}
}
3
Once you create the function app normally and then you create the functions in it manually, find the path where it's saving the functions by default in Kudu. Once you get that you can add : "appSettings": [ { "name": "Project", "value": "src" } ] to the appSettings, and it would by default pick the functions available there. I am not sure of this solution, haven't tried yet, let me know if it works out. Refer: linkAbhirup Guha

3 Answers

15
votes

Are you deploying your function as a package? If so, make sure you set this setting in your template, since it will be removed when you redeploy otherwise:

{ "name": "WEBSITE_RUN_FROM_PACKAGE", "value": "1" }

0
votes

You could try "--mode incremental" parameter although that should be the default when it is not provided.

-2
votes

Yes that should be the expected behavior.

ARM Template is a declarative deployment meaning anytime you deploy it will overwrite anything you have with new template information. The template should always include everything you need.