Azure Bicep Refreshed

Justin Yoo - Apr 23 '21 - - Dev Community

In the previous post, I introduced the very early stage of Project Bicep. At that time, it was the version of 0.1.x, but now it's updated to 0.3.x. You can use it for production, and many features keep being introduced. Throughout this post, I'm going to discuss new features added since the last post.

Azure CLI Integration

While Bicep CLI works as a stand-alone tool, it's been integrated with Azure CLI from v2.20.0 and later. Therefore, you can run bicep in either way.

NOTE: Although Bicep CLI could build multiple files by v0.2.x, it's now only able to build one file at a time from v0.3.x. Therefore, if you want to build multiple files, you should do it differently. Here's a sample PowerShell script, for example.

Because of the Azure CLI integration, you can also provision resources through the bicep file like below:

Bicep Decompiling

From v0.2.59, Bicep CLI can convert ARM templates to bicep files. It's particularly important because still many ARM templates out there have been running and need maintenance. Run the following command for decompiling.

NOTE: If your ARM template contains a copy attribute, bicep can't decompile it as of this writing. In the later version, it should be possible.

Decorators on Parameters

Writing parameters has become more articulate than v0.1.x, using the decorators. For example, there are only several possible SKU values of a Storage Account available, so using the @allowed decorator like below makes the code better readability.

Conditional Resources

You can use ternary operations for attributes. What if you can conditionally declare a resource itself using conditions? Let's have a look. The following code says if the location is only Korea Central, the Azure App Service resource can be provisioned.

Loops

While ARM templates use both copy attribute and copyIndex() function for iterations, bicep uses the for...in loop. Have a look at the code below. You can declare Azure App Service instances using the array parameter through the for...in loop.

You can also use both array and index at the same time.

Instead of the array, you can use the range() function in the loop.

Please note that you MUST use the array expression ([...]) outside the for...in loop because it declares the array of the resources. Bicep will do the rest.

Modules

Personally, I love this part. While ARM templates use the linked template, bicep uses the module keyword for modularisation. Here's the example for Azure Function app provisioning. For this, you need at least Storage Account, Consumption Plan and Azure Functions resources. Each resource can be individually declared as a module, and the orchestration bicep file calls each module. Each module should work independently, of course.

Storage Account

Consumption Plan

Azure Functions

Modules Orchestration

Here's the orchestration bicep file to combine modules. All you need to do is to declare a module, refer to the module location and pass parameters. Based on the references between modules, dependencies are automatically calculated.

NOTE: Unfortunately, as of this writing, referencing to external URL is not supported yet, unlike linked ARM templates.


So far, we've briefly looked at the new features of Project Bicep. As Bicep is one of the most rapidly growing toolsets in Azure, keep using it for your resource management.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player