问题
When deploying an Azure Function App and AppSettings via an ARM Template, is it possible to tell Azure not to delete AppSettings that are not declared in the template?
For example, take the following AppSettings config from the template and imagine that I'm updating an existing Function App. In this case, an AppSetting called storageaccountname_STORAGE would be deleted, which is undesirable as (for example) it has been created to facilitate a binding.
{
"apiVersion":"2016-08-01",
"name":"appsettings",
"type":"config",
"dependsOn":[
"[resourceId('Microsoft.Web/Sites/Slots', variables('functionAppName'), 'Staging')]"
],
"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, ';')]",
"APPINSIGHTS_INSTRUMENTATIONKEY":"[reference(resourceId('Microsoft.Insights/components', variables('applicationInsightsName')), '2014-04-01').InstrumentationKey]",
"FUNCTION_APP_EDIT_MODE":"readwrite",
"FUNCTIONS_EXTENSION_VERSION":"~1",
"WEBSITE_CONTENTAZUREFILECONNECTIONSTRING":"[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listkeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName')), '2015-05-01-preview').key1, ';')]",
"WEBSITE_CONTENTSHARE":"[toLower(variables('functionAppName'))]",
"WEBSITE_NODE_DEFAULT_VERSION":"6.5.0"
}
}
Is there a way to selectivly set AppSettings via an ARM Template, or are the templates simply not capale of functioning as desired for such a scenario?
回答1:
I ran into this problem also a while ago and did not find a solution within an ARM Template.
In my case I solved it by using a PowerShell Script what run after the ARM Template. Maybe you can use some parts of this:
https://gist.github.com/kirkone/2b5996a57a5610a8a41e2bfd1edc37f1
The main part is getting the current values, add or override with the new values and write back the complete list.
This Script is for use with VSTS / TFS but it should give you a hint about how it can be done.
Sorry for not having a better solution but I hope this helps also.
CU
KirK
来源:https://stackoverflow.com/questions/46451822/dont-delete-appsettings-not-declared-in-a-template