Search code examples
azureazure-web-app-serviceazure-functionsazure-resource-managerazure-deployment

Override appSettings of existing azure function app via ARM templates


I have developed an azure timer trigger function. I am taking timer schedule from appSettings of the function app as following.

function.json

function.json

enter image description here

This is working fine for given static schedule. But this schedule should be able to change as per the user requirement from another web application, when user need to change the schedule.

I am struggling to change schedule parameter from external application dynamically. What i was tried is deploy an ARM templatere injecting new schedule values from following ARM template.

    {
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "name": {
      "type": "String"
    },
    "location": {
      "type": "String"
    },
    "subscriptionId": {
      "type": "String"
    },
    "schedule1": {
      "type": "String"
    },
    "schedule2": {
      "type": "String"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites",
      "kind": "functionapp",
      "name": "[parameters('name')]",
      "apiVersion": "2016-03-01",
      "location": "[parameters('location')]",
      "properties": {
        "name": "[parameters('name')]",
        "siteConfig": {
          "appSettings": [
            {
              "name": "schedule1",
              "value": "[parameters('schedule1')]"
            },
            {
              "name": "schedule2",
              "value": "[parameters('schedule2')]"
            }
          ]
        },
        "clientAffinityEnabled": false,
        "reserved": false
      }
    }
  ]
}

However, this is not overriding existing appSettings. Instead, it returns an error "Web site already exists" Is there any method to override appSettings as explained above and restart the function app in order to affect new appSettings parameters.


Solution

  • Per my test, your template works fine on my side.

    Just some information for you to refer.

    This is my function app:

    enter image description here

    Test the template in the portal:

    enter image description here

    Deploy result:

    enter image description here

    Check in the portal:

    enter image description here

    Note: It will overwrite all the settings of the app, before the deployment, there were other settings in my app, currently, there are just two settings.

    Besides, instead of using ARM template, I recommend you to use REST API, essentially, the template is also calling API. You could also use powershell to do it, here is a similar post, you could refer to it.