Azure Function+ARM: merge app settings with current settings

社会主义新天地 提交于 2020-01-05 17:57:26

问题


My deployment is split into two pipelines

  1. deploy infrastructure (run ARM template)
  2. deploy & configure application (upload app, run script)

My ARM template contains an AppSettings array, like this:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
        // ...
  },
  "variables": {
    "functionAppName": "[parameters('appName')]",
    "storageAccountid": "[concat(resourceGroup().id,'/providers/','Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "type": "Microsoft.Web/sites",
      "name": "[variables('functionAppName')]",
      "location": "[parameters('location')]",
      "kind": "functionapp",
      "dependsOn": [],
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
        "siteConfig": {
          "appSettings": [
            {
              "name": "AzureWebJobsStorage",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
            },
            {
              "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
            },
            {
              "name": "WEBSITE_CONTENTSHARE",
              "value": "[toLower(variables('functionAppName'))]"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~2"
            },
            {
              "name": "WEBSITE_NODE_DEFAULT_VERSION",
              "value": "6.5.0"
            },
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(resourceId('microsoft.insights/components/', parameters('applicationInsightsName')), '2015-05-01').InstrumentationKey]"
            }
          ]
        }
      }
    }
  ]
}

During the application deployment, I set new app settings, like this:

az functionapp config appsettings set --resource-group $resourceGroupName 
   --name $functionAppName --settings "foo=bar"

Whenever the infrastructure pipeline is run, it completely removes all app settings which were added via script (e.g. foo). Is there a way to tell ARM to "merge" the deployed AppSettings with the settings defined by the template? Ideally, this should also work when deploying the ARM template for the very first time.

My current workaround is to simply remove the AppSettings part of the ARM template completely.


回答1:


No, you cannot have merge behaviour. I dont think you can set individual app setting values with arm templates, so you'd need to put those keys you add at deployment time to the arm template, or remove appsettings from the arm template.



来源:https://stackoverflow.com/questions/55063731/azure-functionarm-merge-app-settings-with-current-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!