Azure 资源管理器:如何在链接模板中指定可选参数 [英] Azure Resource Manager: How to specify optional parameters in linked templates
问题描述
我正在使用链接模板来部署公共资源.在这种情况下,我正在部署 VM 其中定义了一个可选参数 AdminPassword
,仅在某些情况下才需要(即当参数 PasswordAuthenticationDisabled
设置为 false
时):
I'm making use of linked templates to deploy common resources. In this case I'm deploying a VM which has an optional parameter defined AdminPassword
that is only required in certain scenarios (namely when the parameter PasswordAuthenticationDisabled
is set to false
):
"parameters": {
"AdminPassword": {
"type": "securestring",
"defaultValue": null,
"metadata": {
"description": "Password when password-based authentication isn't disabled"
}
},
"PasswordAuthenticationDisabled": {
"type": "bool",
"defaultValue": "true",
"metadata": {
"description": "Should password-based authentication thorugh SSH be disabled"
}
}
}
我引用的链接模板如下:
I'm referencing the linked template as follows:
{
"type": "Microsoft.Resources/deployments",
"name": "[variables('nameDeploymentVmAttacker1')]",
"apiVersion": "2017-05-10",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(variables('urlTemplates'), '/vm/ubuntu-18.04.json')]"
},
"parameters": {
"Name": {
"value": "[variables('nameVmAttacker1')]"
},
"Region": {
"value": "[resourceGroup().location]"
},
"AdminUsername": {
"value": "[parameters('AdminUsername')]"
},
"AdminSshKey": {
"value": "[parameters('AdminSshKey')]"
},
"VmSize": {
"value": "[parameters('VmSize')]"
},
"VnetName": {
"value": "[variables('nameVnet')]"
},
"PasswordAuthenticationDisabled": {
"value": true
}
}
}
}
没有指定可选参数.这导致 ARM 抱怨缺少参数:部署模板验证失败:'未提供'25'行和'26'列中模板参数'AdminPassword'的值.请参阅 https://aka.ms/arm-deploy/#parameter-file 了解使用详情.
Without the optional parameter specified. This leads to ARM complaining about the missing parameter: Deployment template validation failed: 'The value for the template parameter 'AdminPassword' at line '25' and column '26' is not provided. Please see https://aka.ms/arm-deploy/#parameter-file for usage details.
我如何告诉调用模板尊重参数的可选性并使用默认值?
How can I tell the calling template to honor the optionality of the parameter and just go with the default value?
推荐答案
将 defaultValue 设置为 null 以外的值,例如一个空字符串.对于这种情况,您还可以执行以下操作:https://github.com/Azure/azure-quickstart-templates/blob/master/100-marketplace-sample/azuredeploy.json#L36
Set the defaultValue to something other than null, e.g. an empty string. For this scenario, you can also do something like this: https://github.com/Azure/azure-quickstart-templates/blob/master/100-marketplace-sample/azuredeploy.json#L36
这篇关于Azure 资源管理器:如何在链接模板中指定可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!