Multiple conditions for Bicep resource deployments

After working with Bicep templates we have discovered a useful mechanism, multiple conditions. Multiple conditions provide ways to be more specific in the way we perform conditional deployments and enable us to have more control over the conditions we match on.

Multiple Condition Configuration

To perform multiple conditions in Bicep resource deployments the following needs to be done:

  • Multiple conditions act the same as normal conditions, and first start with an if statement e.g.
resource lock 'Microsoft.Authorization/locks@2017-04-01' = if (lockName != '') {
   name: lockName
   properties: {
       ..
   }
}
  • The difference comes when you want to add another condition. All you need to add is the following comparison operator “&&” e.g.
resource lock 'Microsoft.Authorization/locks@2017-04-01' = if (lockName != '' && resourcelock != 'None') {
    name: lockName
    properties: {
        ..
    }
}

Conclusion

In this blog post, we looked at how to configure multiple conditions for Bicep resource deployments and discussed the benefits it provides. Hopefully you have found this post informative, if you have other bicep tips and tricks let us know and don’t be afraid to share your thoughts.

Read more recent blogs

Get started on the right path to cloud success today. Our Crew are standing by to answer your questions and get you up and running.