Azure Function ARM 模板删除不属于模板文件的现有应用程序设置

标签 azure azure-functions azure-web-app-service azure-rm-template azure-functions-runtime

我使用 ARM 模板创建了具有默认应用程序设置的函数应用程序。不幸的是,当部署 ARM 模板时,它删除了 ARM 模板中未定义的任何应用程序设置。

这是用于函数应用程序的 ARM 模板:

    {
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "functionAppName": {
      "type": "string",
      "defaultValue": "[concat('fnapp', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "The name of the function app that you wish to create."
      }
    },
    "newOrExisting": {
      "type": "string",
      "allowedValues": [
        "new",
        "existing"
      ],
      "metadata": {
        "description": "Choose the app service plan based on these values"
      }
    },
    "existingHostingPlanName": {
      "type": "string",
      "metadata": {
        "description": "The name of the existing hosting plan"
      }
    },
    "existingResourceGroupName": {
      "type": "string",
      "metadata": {
        "description": "The name of the existing resource group"
      }
    },
    "newHostingPlanName": {
      "type": "string",
      "metadata": {
        "description": "The name of the new hosting plan"
      }
    },
    "sku": {
      "type": "string",
      "allowedValues": [
        "D1",
        "F1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P1V2",
        "P2V2",
        "P3V2",
        "I1",
        "I2",
        "I3",
        "Y1"
      ],
      "defaultValue": "S1",
      "metadata": {
        "description": "The pricing tier for the hosting plan."
      }
    },
    "workerSize": {
      "type": "string",
      "allowedValues": [
        "0",
        "1",
        "2"
      ],
      "defaultValue": "0",
      "metadata": {
        "description": "The instance size of the hosting plan (small, medium, or large)."
      }
    },
    "applicationInsightsName": {
      "type": "string",
      "metadata": {
        "description": "The Application Insights Name."
      }
    },
    "storageAccountName": {
      "type": "string",
      "metadata": {
        "description": "Name of the Storage Account."
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "runtime": {
      "type": "string",
      "defaultValue": "dotnet",
      "allowedValues": [
        "node",
        "dotnet",
        "java"
      ],
      "metadata": {
        "description": "The language worker runtime to load in the function app."
      }
    },
    "identityType": {
      "type": "string",
      "metadata": {
        "description": "The Identity type"
      }
    },
    "functionRuntimeVersion": {
      "type": "string",
      "defaultValue": "~3",
      "metadata": {
        "description": "The runtime version for the function app"
      }
    }
  },
  "variables": {
    "serverFarmId": "[ if(equals(parameters('newOrExisting'),'new'),resourceId('Microsoft.Web/serverfarms',parameters('newHostingPlanName')), concat(subscription().id,'/resourceGroups/',parameters('existingResourceGroupName'),'/providers/Microsoft.Web/serverfarms/',parameters('existingHostingPlanName')))]",
    "functionWorkerRuntime": "[parameters('runtime')]"
  },
  "resources": [
    {
      "condition": "[equals(parameters('newOrExisting'),'new')]",
      "type": "Microsoft.Web/serverfarms",
      "apiVersion": "2020-06-01",
      "name": "[parameters('newHostingPlanName')]",
      "location": "[parameters('location')]",
      "sku": {
        "Name": "[parameters('sku')]"
      },
      "properties": {
        "name": "[parameters('newHostingPlanName')]",
        "workerSize": "[parameters('workerSize')]",
        "numberOfWorkers": 1
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2020-06-01",
      "name": "[parameters('functionAppName')]",
      "location": "[parameters('location')]",
      "kind": "functionapp",
      "dependsOn": [
        "[resourceId('microsoft.insights/components', parameters('applicationInsightsName'))]"
      ],
      "identity": {
        "type": "[parameters('identityType')]"
      },
      "properties": {
        "serverFarmId": "[variables('serverFarmId')]",
        "httpsOnly": true,
        "siteConfig": {
          "alwaysOn": true,
          "ftpsState": "FtpsOnly",
          "appSettings": [
            {
              "name": "AzureWebJobsStorage",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';EndpointSuffix=', environment().suffixes.storage, ';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value)]"
            },
            {
              "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';EndpointSuffix=', environment().suffixes.storage, ';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value)]"
            },
                        {
              "name": "WEBSITE_CONTENTSHARE",
              "value": "[toLower(parameters('functionAppName'))]"
            },
            {
              "name": "WEBSITE_RUN_FROM_PACKAGE",
              "value": "1"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "[parameters('functionRuntimeVersion')]"
            },
            {
              "name": "WEBSITE_NODE_DEFAULT_VERSION",
              "value": "~10"
            },
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(resourceId('microsoft.insights/components', parameters('applicationInsightsName')), '2020-02-02-preview').InstrumentationKey]"
            },
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "[variables('functionWorkerRuntime')]"
            }
          ]
        }
      }
    },
    {
      "type": "microsoft.insights/components",
      "apiVersion": "2020-02-02-preview",
      "name": "[parameters('applicationInsightsName')]",
      "location": "[parameters('location')]",
      "tags": {
        "[concat('hidden-link:', resourceId('Microsoft.Web/sites', parameters('applicationInsightsName')))]": "Resource"
      },
      "properties": {
        "ApplicationId": "[parameters('applicationInsightsName')]",
        "Request_Source": "IbizaWebAppExtensionCreate"
      }
    }
  ],
  "outputs": {}
}

我已提及this git hub 问题,但它仍然是开放的。

那么,有人可以建议我如何解决这个问题吗?

最佳答案

这是正常现象,当你部署模板时,有两种模式,CompleteIncremental,但即使使用Incremental模式下,如果您提供新值,则作为 Microsoft.Web/sites/config 子资源的 appsettings 将被覆盖(Web 应用程序和函数应用程序相同)。

引用 - https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/deployment-modes#incremental-mode

enter image description here

因此,就您的情况而言,如果您想保留默认设置,您还需要将它们添加到模板中。

关于Azure Function ARM 模板删除不属于模板文件的现有应用程序设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65203047/

相关文章:

Azure 和旧的 .Net 远程处理

powershell - Azure Powershell 用于停止订阅中的 VM

azure - Multi-Tenancy Azure 动态通配符 CName

c# - Azure Functions 无法从 ABCpdf Nuget 包加载 DLL

c# - Azure 搜索为什么 OCRed 文本未按正确的顺序合并到 merged_content 字段中?

azure - windows azure网站预览A记录专用IP

azure - 如何确定Azure中应用程序服务计划CPU百分比100%的原因?

c# - 授权属性在 Azure 上无法使用 OWIN

c# - 结合 WPF + WCF + Entity Framework 的好例子

c# - Azure函数不向服务总线主题发送消息