How to Deploy Bicep Resources to Azure Using Conditions

This blog post will show you how to deploy Bicep resources to Azure using conditions.

Azure provides a great platform for hosting applications, and by using conditions, you can ensure that your resources are deployed in the most efficient way possible. Let’s get started!

To deploy Bicep resources to Azure using conditions, you first need to create a deployment template. The template will specify the resources that you want to deploy and the conditions under which they should be deployed.

The following example shows how to deploy a MySQL Server to Azure using a condition. The MySQL server will only be deployed if the parameter deploymysql is set to true (Because the parameter is set to false the server will not deploy).

param deploymysql bool = false

Below is the end to end bicep template.

param deploymysql bool = false
param mysqlsrv object = {
  skuname: 'GP_Gen5_2' 
  location: resourceGroup().location
  tier: 'GeneralPurpose'
  capacity: 2
  servername: 'ntweeklysql10'

}

@secure()
param administratorLoginPassword string 


resource mysqlserver 'Microsoft.DBforMySQL/servers@2017-12-01' = if (deploymysql) {
  name: mysqlsrv.servername
  location: mysqlsrv.location
  
 sku: {
    name: mysqlsrv.skuname
    capacity: mysqlsrv.capacity
    tier: mysqlsrv.tier
     

    
 }
 properties: {
   createMode: 'Default'
   administratorLoginPassword: administratorLoginPassword
   administratorLogin: 'myadmin'
 }
}

Leave a comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.