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
}
}
}
}
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With