动态的应用程序设置阵列内容
我有以下简化的手臂模板(我遗漏了某些零件以使其更可读)。我有一个称为privateKeycertificateThumbPrint的参数
。如果填写此参数,我想将appsetting wording_load_certificates
设置为某个值。如果参数为空,我不想设置该值。因此,基于AppSettings
数组中的元素是基于private keypercertificateThumbPrint
parameter的内容的动态。
我似乎没有为此找到解决方案。用户酶似乎很简单。首先,我尝试添加其他microsoft.web/stites/config/appsettings
资源,仅使用worges_load_certificates
键。但是这样做可以从应用程序中删除所有已经存在的应用程序集。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
...
"PrivateKeyCertificateThumbprint": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "The thumbprint of the client certificate used by the application"
}
}
},
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"name": "[parameters('AppResourcename')]",
"identity": {
"type": "SystemAssigned"
},
"Location": "[parameters('Location')]",
"kind": "[parameters('SitesKind')]",
"properties": {
"siteConfig": {
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[if(empty(parameters('AppinsResourceName')), '', reference(resourceId('microsoft.insights/components/', parameters('AppinsResourceName')), '2015-05-01').InstrumentationKey)]"
},
{
"name": "ApplicationInsightsAgent_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "WEBSITE_HEALTHCHECK_MAXPINGFAILURES",
"value": "5"
},
{
"name": "WEBSITE_LOAD_CERTIFICATES",
"value": "[parameters('PrivateKeyCertificateThumbprint')]"
}
],
"healthCheckPath": "[parameters('HealthCheckPath')]"
}
...
}
]
}
I have the following simplified ARM template (I left out certain parts to make it more readable). I have a parameter called PrivateKeyCertificateThumbprint
. If this parameter is filled in, I want to set the appsetting WEBSITE_LOAD_CERTIFICATES
to a certain value. If the parameter is empty, I do not want to set the value. So the elements in the appSettings
array are sort of dynamic based on the content of the PrivateKeyCertificateThumbprint
parameter.
I do not seem to find a solution for this in ARM. The usecase seems so simple. First I tried to add an additional Microsoft.Web/sites/config/appsettings
resource with only the WEBSITE_LOAD_CERTIFICATES
key. But doing that removes all the already existing appsettings from the application.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
...
"PrivateKeyCertificateThumbprint": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "The thumbprint of the client certificate used by the application"
}
}
},
"resources": [
{
"type": "Microsoft.Web/sites",
"apiVersion": "2018-11-01",
"name": "[parameters('AppResourcename')]",
"identity": {
"type": "SystemAssigned"
},
"Location": "[parameters('Location')]",
"kind": "[parameters('SitesKind')]",
"properties": {
"siteConfig": {
"appSettings": [
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[if(empty(parameters('AppinsResourceName')), '', reference(resourceId('microsoft.insights/components/', parameters('AppinsResourceName')), '2015-05-01').InstrumentationKey)]"
},
{
"name": "ApplicationInsightsAgent_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "WEBSITE_HEALTHCHECK_MAXPINGFAILURES",
"value": "5"
},
{
"name": "WEBSITE_LOAD_CERTIFICATES",
"value": "[parameters('PrivateKeyCertificateThumbprint')]"
}
],
"healthCheckPath": "[parameters('HealthCheckPath')]"
}
...
}
]
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了清楚起见,我使用了a bicep template 。
在这里,我定义了一个带有默认应用程序的变量。然后,如果CERT THUMBPRINT不是空的,我正在添加额外的应用程序设置:
use az cli ,然后您可以生成手臂temnplate:
生成的手臂模板看起来像:
For clarity, I used a bicep template.
Here I've defined a variable with default appsettings. Then if the cert thumbprint is not empty, I'm adding the extra app setting:
Using Az CLI, you can then generate the ARM temnplate:
the generated ARM template looks like that:
我终于设法通过使用功能使它在手臂上工作。我创建了3个功能,这些函数创建了3个带有参数的子数组,我只能在资源本身中获得的值。然后,我将Concat与IF结合使用,以有条件地将零件添加到资源中的设置数组中。
I finally managed to get it to work in ARM by using functions. I created 3 functions that created 3 sub arrays with as parameters, values I could only get in the resource itself. I then used a concat in combination with an if, to conditionally add parts to the settings array in the resource.