Bicep

Coding standard for bicep

To ensure code is of high quality is easy to read and is maintainable it is important to agree on some standard when it comes to bicep files. I like to use the following set of standards for my bicep code.

  • Group elements by element type. All Bicep files must be grouped by element type in the following order:
  • TargetScope
  • Param
  • Var
  • Resource
  • Output
  • Add a blank line between each element section.
  • Use param for input parameters
  • Use variables to calculate new values from existing parameters or properties
  • Primary resources goes at the top of the resource section followed by supporting resource types.
  • User variables and loops to deploy similar resources.
  • Only add dependsOn if the template fails to deploy without it. Rather rely on symbolic name nesting to let ARM auto detect the deployment order.
  • Use the parent property to define the relationship between parent and child resources
  • When using outputs don’t construct output values use the built in properties instead.
  • Don’t comment out resource definitions in production code remove it completely.
  • Add comments to your code to clarify complexities in code.
  • Add the @description() decorator to params, vars, resources and outputs to explain the purpose.
  • Add a manifest at the top of each file.
/*
    SYNOPSIS: Module for provisioning Azure SQL server and database.
    DESCRIPTION: This module provisions an Azure SQL server and a database, and configures the server to accept connections from within Azure.
    VERSION: 1.0.0
    OWNER TEAM: Website
*/

Bicep Playground

The Bicep Playground is a web-based tool that allows you to write, test, and debug Bicep code without installing any software on your local machine. It provides a live side-by-side comparison of Bicep and equivalent JSON, allowing you to compare the implementations of the same infrastructure. You can edit both Bicep and JSON files live and see the effects of a change in one, live in the other . The Bicep Playground is a useful tool if you do not wish to install the tooling locally, but still want to review the syntax and have a go at verifying what would be the result of your Bicep file or what would be the equivalent of your ARM template in Bicep.

Link: Bicep Playground