Use Objects With a Bicep Template

This blog post will show how to create an object with Bicep and use it in a Bicep template.

Objects

In our previous post, we showed how to declare a parameter with Bicep and the types of parameters available to us. One of the available parameters is an object type.

Objects in Bicep allow us to create a parameter with multiple parameters type (string and int). We can then use the object to hold configuration details of a resource, as you will see soon.

Example

I have part of a configuration template in the example below that creates a MySQL Server.

In the first six lines of the code below, I declare the object and populate it with the configuration properties of the MySQL Server.

In the resource part of the configuration, I’m using the information that is in the object to create the MySQL Server.

To access information inside the object, I’m using the following format.

mysqlsrv.servername

You can see the code below.

param mysqlsrv object = {
  skuname: 'GP_Gen5_2' 
  location: resourceGroup().location
  tier: 'GeneralPurpose'
  capacity: 2
  servername: 'ntweeklysql10'
}
resource mysqlserver 'Microsoft.DBforMySQL/[email protected]' = {
  name: mysqlsrv.servername
  location: mysqlsrv.location

 sku: {
    name: mysqlsrv.skuname
    capacity: mysqlsrv.capacity
    tier: mysqlsrv.tier
 }


Posted

in

,

by

Comments

One response to “Use Objects With a Bicep Template”

  1. […] the below Bicep template, we are creating a MySQL server using a Bicep object which is suitable in use cases like this where we can hold all the configuration inside an object […]

Leave a Reply

Your email address will not be published. Required fields are marked *

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