Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Infrastructure as Code with Azure Bicep

You're reading from   Infrastructure as Code with Azure Bicep Streamline Azure resource deployment by bypassing ARM complexities

Arrow left icon
Product type Paperback
Published in Feb 2022
Publisher Packt
ISBN-13 9781801813747
Length 230 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Yaser Adel Mehraban Yaser Adel Mehraban
Author Profile Icon Yaser Adel Mehraban
Yaser Adel Mehraban
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Section 1: Getting Started with Azure Bicep
2. Chapter 1: An Introduction to Azure Bicep FREE CHAPTER 3. Chapter 2: Installing Azure Bicep 4. Chapter 3: Authoring Experience 5. Chapter 4: Compiling and Decompiling Bicep Files 6. Section 2: Azure Bicep Core Concepts
7. Chapter 5: Defining Resources 8. Chapter 6: Using Parameters, Variables, and Template Functions 9. Chapter 7: Understanding Expressions, Symbolic Names, Conditions, and Loops 10. Chapter 8: Defining Modules and Utilizing Outputs 11. Section 3: Deploying Azure Bicep Templates
12. Chapter 9: Deploying a Local Template 13. Chapter 10: Deploying Bicep Using Azure DevOps 14. Chapter 11: Deploying Bicep Templates Using GitHub Actions 15. Chapter 12: Exploring Best Practices for Future Maintenance 16. Other Books You May Enjoy

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.

Figure 1.2 – Visual Studio Code Bicep extension

Figure 1.2 – Visual Studio Code Bicep 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.

You have been reading a chapter from
Infrastructure as Code with Azure Bicep
Published in: Feb 2022
Publisher: Packt
ISBN-13: 9781801813747
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime