How does it work?
Now that you know what Bicep is and why it was created, it is time to learn how it works and what it takes to get started with it, which you will learn in this section.
Authoring experience
You can create and use Bicep files with Visual Studio Code using the official Bicep Visual Studio Code extension, which can be found at https://github.com/Azure/bicep/blob/main/docs/installing.md#bicep-vs-code-extension.
This means it really feels like a native experience, with all the bells and whistles of autocorrection, IntelliSense, validation warnings, and so on.
To make it even more exciting, both the Azure CLI and Azure PowerShell have built-in support for Bicep. That means you can compile and deploy a Bicep file just like you were doing with ARM templates. The transpilation happens behind the scenes for you and deployment will run afterward.
To give you an example, with ARM templates you use the az deployment group create
command to start a new deployment, like so:
az group deployment create \ -g myResourceGroup -n myDeployment \ --template-file ./deploy.json \ --parameters ./deploy.parameters.json \ --parameters "sqlSAPassword=$password"
The procedure with Bicep would look very similar, if not identical, since the Azure CLI and PowerShell already support Bicep files as templates:
az deployment group create \ -g myResourceGroup -n myDeployment \ --template-file ./main.bicep \ --parameters @parameters.json
And you should have your template deployed shortly after the command is successful. This is great, since you can easily use your Bicep files rather than compiling them first and then deploying them using one of these scripting tools, which adds extra time to your deployments and potentially adds unnecessary complexity to your pipeline steps.
What happens to my ARM templates?
If you already have ARM templates you wish to migrate to Bicep, the easiest solution is to use its CLI to decompile your JSON files by running the following command:
az bicep decompile --file azuredeploy.json
We will delve into this in much more detail in our upcoming chapters, but I just wanted to let you know in advance that there is no need to worry about the migration of your ARM templates into Bicep. In fact, since even the deployment commands are the same, there would be minimal changes required to your pipeline scripts.
Warning
As with any other tool, decompilation might result in a scenario where it would result in warnings or errors, which should be resolved by you. The possibility is not that high, but it might happen. One of the reasons might be that you are using copy loops or nested templates.
Bicep CLI
Bicep comes with its own cross-platform CLI, which will then be used by the Azure CLI and Azure PowerShell behind the scenes to compile/decompile Bicep/ARM template files. We will talk about this in much more detail later.
For example, if you wanted to decompile an ARM template to Bicep as we saw before, you would use a script like so:
bicep decompile --file azuredeploy.json
We will review this feature in much more detail later in the book.