5 fun and easy ways to transition to Bicep and save time!

Freek Berson
6 min readFeb 13, 2023

--

In you are into Infrastructure as Code for Azure, you probably have heard about Bicep by now, or maybe (hopefully) you’re actively using it. If not, this blog post provides some guidance to help you with your personal transformation (or should I say transpilation 😊) towards using Bicep. In other words, if you’ve been developing ARM Templates (JSON) a lot, here are some cool and fast ways to learn Bicep using VSCode.

Just in case you’ve never heard about Bicep, what is it in a nutshell?

Bicep is like having a magic wand for Azure infrastructure as code. It’s a new language that makes it super easy to create and manage Azure resources in a declarative manner. You simply write down what you want your Azure environment to look like, and Bicep takes care of the heavy lifting for you. It’s like ordering a pizza, but instead of pizza, you get a fully configured Azure environment, and instead of a delivery guy, you have Bicep! Just wave your Bicep wand and poof, your Azure resources appear exactly as you specified.*
* Full disclose I had ChatGTP write this fun description of Bicep! 😊

1. Decompile
Right click any existing ARM Template based on JSON and simply select “Decompile to Bicep”. Within a second you are presented with the Bicep equivalent of your ARM Template. This is a super easy way of reverse engineering and learn Bicep. Note, decompile is always based on best effort. If the template can be decompiled, it will always result in a valid Bicep Template but might not be 100% optimized. It can however provide you with a great head start. In case you are wondering, yes you can also decompile using the Az CLI, PowerShell and the Bicep executable.

In you are into Infrastructure as Code for Azure, you probably have heard about Bicep by now, or maybe (hopefully) you’re actively using it. If not, this blog post provides some guidance to help you with your personal transformation (or should I say transpilation 😊) towards Bicep. In other words, if you’ve been developing ARM Templates (JSON) a lot, here are some cool and fast ways to learn Bicep using VSCode.

Just in case you’ve never heard about Bicep, what is it in a nutshell?

Bicep is like having a magic wand for Azure infrastructure as code. It’s a new language that makes it super easy to create and manage Azure resources in a declarative manner. You simply write down what you want your Azure environment to look like, and Bicep takes care of the heavy lifting for you. It’s like ordering a pizza, but instead of pizza, you get a fully configured Azure environment, and instead of a delivery guy, you have Bicep! Just wave your Bicep wand and poof, your Azure resources appear exactly as you specified.*

* Full disclose I had ChatGTP write this fun description of Bicep! 😊

1. Decompile

Right click any existing ARM Template based on JSON and simply select “Decompile to Bicep”. Within a second you are presented with the Bicep equivalent of your ARM Template. This is a super easy way of reverse engineering and learn Bicep. Note, decompile is always based on best effort. If the template can be decompiled, it will always result in a valid Bicep Template but might not be 100% optimized. It can however provide you with a great head start. In case you are wondering, yes you can also decompile using the Az CLI, PowerShell and the Bicep executable.

Add alt text

2. Paste JSON as Bicep
If you have any existing JSON code in your clipboard, for example copied from any resource online, you can directly copy it as Bicep code in VSCode. How cool is that? 😊. With a flick of a wand (or rather, a paste into VSCode), your JSON code is transformed into beautiful, readable Bicep code.

It’s important to note that this feature is currently in its experimental phase, and as such, may have limitations or unfinished elements.

3. Insert Resource
To utilize this feature, you will need to follow these steps:

- Copy the resource ID of an existing resource within your Azure environment.
- In your Bicep file, perform a right-click and select “Insert Resource” from the context menu.
- Paste the copied resource ID into the designated field.
- Upon executing these steps, the resource will be instantly available in Bicep, ready for use within your infrastructure as code deployment.

4. Local ARM Template (JSON) as a module
If you have existing ARM Templates in JSON and, for whatever reason, don’t want to decompile to Bicep, you can also use an ARM Template as a module. Below is the syntax to use, this is the exact same syntax as Bicep modules. Very convenient and easy to use!

5. Template Spec as a module
Similar to option 4, you can also leverage an ARM Template as a module directly from a Template Spec resource in Azure. Create a Template Spec resource in Azure, paste your ARM Template in there, and now you can reference it as a module as shown below.

To conclude
If you are currently developing ARM Templates and it brings you everything you need, nothing is stopping you from continuing to use it, its fully supported. I’m not saying ARM Templates are bad and you must switch to Bicep. If you currently are using ARM Templates and you are struggling with the complexity and limitations…it’s never too late to learn Bicep. And if you’re already familiar with Visual Studio Code (VSCode), it’s a great tool to get started with Bicep. VSCode offers a wide range of plugins and extensions that make it easier to write, debug, and deploy Bicep templates. You can use the VSCode IntelliSense feature to get suggestions and auto-completion as you type, making it easier to write correct Bicep code, including a way to visualize as you type. Bicep removes a lot of the syntax overhead of ARM Templates, providing clean coding experience, and also provides better options to reuse code based on modules and registries.

There is much more to the story of course. If you are interested in getting started with Bicep, I published a book to help you jump start on Bicep, posted lots of example code on my GitHub, and created a collection links to on demand sessions on Bicep that I (co)presented in the past.

Questions? Feel free to reach out via Twitter, LinkedIn, or E-mail!

--

--

Freek Berson

Empowering hybrid and remote workforces with a digital workspace from any device, anywhere. EUC Enthusiast, Microsoft MVP, 🎤 public speaker, 📚 Author.