I understand there is option to have conditional output for property values, but is it possible to have conditional property itself. For example I have template which creates Microsoft.Compute/VirtualMachine
and it's the same template for both Windows and Linux. But for windows I need to specify property which do not exist for Linux ("licenseType": "Windows_Server")
. Presense of this property will fail deployment with error The property 'LicenseType' cannot be used together with property 'linuxConfiguration'
I'm trying to figure out if it's possible to have this property included only for Windows images while keeping template the same?
A common ask from customers is, “how can we use conditions in our ARM templates, so if a user selects parameter A, then resource A is created. If not, resource B should be created?”. The only way you could achieve this, would be by using nested templates and have a mainTemplate to manipulate the deployment graph.
We now have proper conditional logic in ARM templates! I blogged a few weeks ago about a workaround that would let you have this sort of logic using nested templates, but this was very much a temporary solution. With this new functionality, conditions are now fully implemented into the language!
There are several functions in ARM templates that can evaluate input and return true or false. so, just to be clear, there is no way of placing conditions on properties of a resource only on the resource deployment itself? makes no sense. this is just a repost of official documentation in other words. nothing is coming in this field any time soon.
With this new functionality, conditions are now fully implemented into the language! The ARM template language now includes the “condition” key, which can be applied to a resource to determine whether or not that resource is executed.
yes it is possible, but hacky. several options:
let me expand number two a bit:
"variables": {
"baseObject": {
"propertyOne": "xxx",
"propertyTwo": "yyy
}
"additionalObject: {
"optionalProperty": "zzz"
}
}
and then in your object you can do:
"property": "[if(something, variables('baseObject'), # new line for readability
union(variables('baseObject'), variables('additionalObject') ))]"
Here is what I end up doing based on a previous answer as well as comments
"isWindowsOS": "[equals(parameters('ImageReferenceOffer'), 'WindowsServer')]"
"properties": {
"licenseType": "[if(variables('isWindowsOS'), 'Windows_Server', json('null'))]",
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