我正在使用链接模板来部署公共资源。在这种情况下,我将部署一个VM,它具有一个定义的AdminPassword
可选参数,仅在某些情况下才需要(即,当参数PasswordAuthenticationDisabled
设置为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"
}
}
}
我引用的链接模板如下:
{
"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抱怨缺少参数: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.
如何告诉调用模板遵守参数的可选性,而仅使用默认值?
答案 0 :(得分:0)
将defaultValue设置为非null的值,例如一个空字符串。对于这种情况,您还可以执行以下操作:https://github.com/Azure/azure-quickstart-templates/blob/master/100-marketplace-sample/azuredeploy.json#L36