Exploring conditions
You have already seen a few examples of using conditions in templates using conditional operators. Conditions can be very beneficial in many different scenarios, whether you want to decide whether a resource should be deployed or not or when calculating a value. But how can we apply these during deployment? That is when deploy conditions come to the rescue.
Deploy condition
You can pass in a parameter or use a variable to decide whether a resource should be deployed or not using this condition. Here is an example:
param deployZone bool resource zone 'Microsoft.Network/dnszones@2018-05-01' = if (deployZone) { name: 'myZone' location: 'global' }
Notice the if
keyword before the resource definition. This is all you need to enforce your condition during deployment.
New or existing resource
You can also use the same approach to check whether a resource is new or existing during deployment. To achieve...