Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Infrastructure as Code with Azure Bicep
Infrastructure as Code with Azure Bicep

Infrastructure as Code with Azure Bicep: Streamline Azure resource deployment by bypassing ARM complexities

Arrow left icon
Profile Icon Yaser Adel Mehraban
Arrow right icon
$28.99 $41.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (14 Ratings)
eBook Feb 2022 230 pages 1st Edition
eBook
$28.99 $41.99
Paperback
$51.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Yaser Adel Mehraban
Arrow right icon
$28.99 $41.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4 (14 Ratings)
eBook Feb 2022 230 pages 1st Edition
eBook
$28.99 $41.99
Paperback
$51.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$28.99 $41.99
Paperback
$51.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Infrastructure as Code with Azure Bicep

Chapter 1: An Introduction to Azure Bicep

In this chapter, you're going to learn what Azure Bicep is, and you'll get a quick bit of background on why it was created and what problems it is trying to solve. There will be a comparison with its predecessor, ARM templates, and at the end, you will learn about some of its limitations.

This chapter will give you insights into the reason why Microsoft went to all the trouble of creating Azure Bicep, even though there are already many different third-party tools out there with similar functionalities and feature sets. It is important to learn the reasoning to be able to learn the language without any bias and make practical use of its powerful features.

In this chapter, we are going to cover the following main topics:

  • What is Azure Bicep?
  • Why was it created?
  • How does it work?

Technical requirements

To make the most of this chapter, you will need to have a basic understanding of Infrastructure as Code (IaC), Azure ARM templates, and the Azure CLI. The code used throughout this chapter is stored in this GitHub repository: https://github.com/PacktPublishing/Infrastructure-as-Code-with-Azure-Bicep/tree/main/Chapter01.

What is Azure Bicep?

In this section, you will learn Azure Bicep and what it offers to developers and DevOps teams. There will be a few code snippets to get your eyes familiar with the syntax and, finally, an overview of its components and building blocks. But before we begin, let's review some concepts to make sure we are on the same page.

IaC

Currently, many companies try to automate their infrastructure creation and maintenance. To do that, and to further keep track of what is happening or has happened in their environments, they use a set of scripts or code files alongside tools and processes that streamline the whole deployment for them.

This practice is called IaC and helps every team to safely establish and configure the required infrastructure for their applications and solutions. This practice became even more simplified when all cloud providers added the ability for their customers to use it, which in terms of Microsoft is called Azure Resource Manager (ARM) templates.

ARM templates

Microsoft Azure used to have a deployment model called classic, which helped users deal with individual services (called cloud services) using three components: service definition, service configuration, and service package. There is no need to delve into the details of these concepts; suffice to say that soon they realized this approach needed to change if they wanted to allow their users to leverage the full potential of IaC.

That is when ARM was introduced as a new way of deploying cloud services in Azure that supported other tools, such as the Azure portal, the Azure CLI, Azure PowerShell, and all their SDKs. Here is what the new deployment model looks like:

Figure 1.1 – Azure Resource Manager

Figure 1.1 – Azure Resource Manager

As you can see, it's a much better-unified model, which allows their customers to deploy their resources using a centralized management layer. In addition to that, Microsoft introduced ARM templates, JavaScript Object Notation (JSON) documents, which would declare what resources are needed to be deployed and what the resource manager will use to deploy them in a group, along with their configuration and other files if needed.

Using ARM templates, developers and DevOps engineers can create repeatable deployments that offer auditability, extensibility, testing, modularity, previews, detailed logs, and a status update on the deployments as resources are getting created or modified.

Azure Bicep

Even though ARM templates are great to begin with, it turns out that JSON is not the ideal format to use, especially when the number of resources is high or the deployment model gets complex with time. So, Microsoft started to work on a project called Bicep as a revision to ARM templates to overcome some of the issues people were facing.

Azure Bicep is a Domain-Specific Language (DSL) that has all the benefits of ARM templates, but instead of using JSON, it uses a new language to overcome its shortcomings. It is designed to simplify the authoring experience of IaC and bring more integration with other tools, such as the Azure CLI and Visual Studio Code.

It is worth mentioning that Azure Bicep files will get transpiled to ARM templates very much like how TypeScript files transpile to JavaScript. This means every type, resource, and property that is valid in an ARM template is valid in Bicep as well. We will not go into the details of what a Bicep file looks like, but to pique your curiosity, here is the famous Hello World! in Bicep language:

param message string
var hello = 'Hello World! - Hi'
output helloWorld string = '${hello} ${message}'

When you compile this file, you will get an ARM template that looks like the following:

{
  „$schema": „https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "dev",
      "templateHash": "14991011523779832704"
    }
  },
  "parameters": {
    "message": {
      "type": "string"
    }
  },
  "functions": [],
  "variables": {
    "hello": "Hello World! - Hi"
  },
  "resources": [],
  "outputs": {
    "helloWorld": {
      "type": "string",
      "value": "[format('{0} {1}', variables('hello'), parameters('message'))]"
    }
  }
}

It is amazing how simplified the Bicep file is, don't you agree? Some of the advantages of Azure Bicep are as follows:

  • Support for all current resource providers
  • A syntax that simplifies the IaC and can reduce a huge amount of code compared to ARM templates
  • No need to manage any state (compared to some third-party tools, such as Terraform)
  • Native integration with Microsoft tools, such as the Azure CLI and Visual Studio Code
  • A modular structure that allows you to break your code and create your IaC with peace of mind
  • Backed up by Microsoft support plans
  • Native integration with other Azure resources, such as Azure Policy and Blueprints

Why was it created?

Now is the time to delve into why Microsoft felt there was a need to create another revision on ARM templates, which will be covered in this section. In addition, we will have a look at the rationale behind when to use third-party tools such as Pulumi or Terraform, and when to go with Bicep.

Why create a new revision?

ARM templates had some issues that were causing many customers to complain about the usage of JSON and its limitations. The first thing that was causing some pain was the way validation worked in ARM templates. Often, the template validation passed but the deployment would fail.

Another reason was not having to comment in the template, especially if the deployment model was very complex. I am not a fan of commenting in code or any script for that matter, but the lack of commenting, even small comments to deliver a hint to the next maintainer or team member, was not something people were happy about.

And the last valid reason was how parameters would be duplicated for different resources or environments. Given the fact that ARM templates themselves are reusable, this was not ideal and would make maintaining the parameter files a nightmare, although they might contain the same value.

To overcome these issues, Microsoft started to investigate different existing tools and new ways to enhance the functionality of ARM templates and, in the end, they ended up with the Bicep language, with its own syntax.

They mentioned in their GitHub repository that they went through more than 120 customer calls and surveyed their Most Valuable Professionals (MVPs) network, and evaluated and even prototyped a version written in TypeScript, but eventually decided that Bicep should have its own syntax.

And to me, it is a valid reason, since the majority of companies will use DevOps engineers or even cloud enablement teams to implement and maintain the IaC. Many of those people do not have familiarity with programming languages, which means that using a high-level language would incur a learning curve many companies cannot afford. On the other hand, many of those folks know scripting languages and can learn Bicep really fast without too much effort.

What about current third-party tools?

Another question people usually ask is why they can't use current tools, such as Pulumi or Terraform. For Pulumi, I have already explained the barrier of knowing a required programming language and the learning curve that would follow. For those who are comfortable using Terraform or are already using it, there would not be any reason to shift to Bicep at all. Of course, that is whether you are happy to pay the price to use Terraform Cloud when Bicep is a free tool.

In fact, Microsoft has already invested in creating a set of documentation to streamline the learning material in their DevOps site regarding using Terraform on Azure, which can be found at https://azure.microsoft.com/en-au/solutions/devops/terraform.

That said, many organizations – some of which I personally have worked with – are using ARM templates and are looking for a solution with the least overhead to move on. For those people, Bicep works well because they are already familiar with concepts such as built-in functions, types, API versions, and so on.

Furthermore, for those who have not started their journey in IaC, it would be much easier to start with something that has integration with the tools they would use, such as the Azure CLI and Visual Studio Code, with as little learning as possible, keeping in mind that Bicep is now supported by Microsoft support plans.

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.

Summary

In this chapter, we had a lot to discuss, a few concepts to agree on, and a few comparisons to make. You learned what IaC is very briefly, and then I made sure you knew about ARM templates, since that is the whole reason Bicep was created.

That was then followed by what Azure Bicep is, and you learned that it is not a new programming language and is a revision of ARM templates, with its own syntax. You saw why there was a need for creating yet another solution to implement IaC, even though there are plenty of tools, such as Pulumi and Terraform, out there. We talked about the cloud enablers not knowing any programming languages and the learning curve that would be in place if they had to learn a high-level language to do their day-to-day jobs.

Once that was settled, you learned how Bicep works and got to know the tools that can be used to create, compile, and deploy your resources using Bicep. We saw the built-in integration with the Azure CLI and Azure PowerShell, and how Bicep has its own CLI, which makes it easy for you to even decompile an ARM template into a Bicep file.

In the next chapter, we will get started with Bicep by going through how to install it on multiple different platforms.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn Azure Bicep from an official Microsoft trainer
  • Master the authoring experience to make your Infrastructure as Code journey seamless
  • Go beyond writing good templates with the help of advanced tips and tricks

Description

It’s no secret that developers don’t like using JSON files to declare their resources in Azure because of issues such as parameter duplication and not being able to use comments in templates. Azure Bicep helps resolve these issues, and this book will guide you, as a developer or DevOps engineer, to get the most out of the Bicep language. The book takes you on a journey from understanding Azure Resource Manager (ARM) templates and what their drawbacks are to how you can use Bicep to overcome them. You will get familiar with tools such as Visual Studio Code, the Bicep extension, the Azure CLI, PowerShell, Azure DevOps, and GitHub for writing reusable, maintainable templates. After that, you’ll test the templates and deploy them to an Azure environment either from your own system or via a continuous integration and continuous delivery (CI/CD) pipeline. The book features a detailed overview of all the Bicep features, when to use what, and how to write great templates that fit well into your existing pipelines or in a new one. The chapters progress from easy to advanced topics and every effort has been put into making them easy to follow with examples, all of which are accessible via GitHub. By the end of this book, you’ll have developed a solid understanding of Azure Bicep and will be able to create, test, and deploy your resources locally or in your CI/CD pipelines.

Who is this book for?

This book is for cloud engineers, developers, and DevOps engineers who are responsible for writing templates to deploy resources in Microsoft Azure and contributing to CI/CD pipelines. Professionals who want to get started with DevOps and Infrastructure as Code when it comes to working with Microsoft Azure will also benefit from reading this book. Readers are expected to have a basic understanding of CI/CD concepts, must have worked with ARM templates to deploy resources to Azure, and must have used or be familiar with Azure DevOps or GitHub Actions for their CI/CD pipelines.

What you will learn

  • Get started with Azure Bicep and install the necessary tools
  • Understand the details of how to define resources with Bicep
  • Use modules to create templates for different teams in your company
  • Optimize templates using expressions, conditions, and loops
  • Make customizable templates using parameters, variables, and functions
  • Deploy templates locally or from Azure DevOps or GitHub
  • Stay on top of your IaC with best practices and industry standards

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 10, 2022
Length: 230 pages
Edition : 1st
Language : English
ISBN-13 : 9781801815710

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Feb 10, 2022
Length: 230 pages
Edition : 1st
Language : English
ISBN-13 : 9781801815710

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 147.97
Mastering Azure Security
$48.99
Infrastructure as Code with Azure Bicep
$51.99
The Road to Azure Cost Governance
$46.99
Total $ 147.97 Stars icon
Banner background image

Table of Contents

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

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.4
(14 Ratings)
5 star 78.6%
4 star 7.1%
3 star 0%
2 star 0%
1 star 14.3%
Filter icon Filter
Top Reviews

Filter reviews by




Tomica Kaniski Jun 06, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Really happy that I purchased this book! As it turns out, it is really a wonderful resource for learning Bicep language. Yas slowly builds up your Bicep knowledge, step by step, page by page, and once you're finished with the book, you have very good understanding of why Bicep was created, how to use it in your projects and where it fits best. There are also numerous best practices, hints on dealing with your code, introducing Azure DevOps and GitHub actions into your workflows and much more! In my opinion - worth reading!
Amazon Verified review Amazon
Jeff Brown Feb 11, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I had the pleasure of receiving an early copy of this book. It is an excellent resource for getting started with Bicep. I initially looked through the content at a high level and then used it as a reference guide when writing some Bicep code recently. Need to know how to define parameters? Done. Are you working on modules? Done! Yaser provides easy-to-follow instructions and examples to take beginner or advanced IaC code writers to Bicep fluency.
Amazon Verified review Amazon
Inknochen Feb 10, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
In this book you'll find an easy-to-read map on the why Bicep is a thing now, and as all the other technologies you may choose to adopt, knowing how this came about it helps realizes its full potential to you. I like the way Yas presents this as an opportunity to modernize the IaC and how you deploy this along aside your current model with the same tools and how to migrate to the new model with ease. I recommend this book as it'll have all you need to start using it right away.
Amazon Verified review Amazon
Anil Mahadev Feb 10, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book takes the beginner to intermediate level of ARM template users to embrace the next gen Bicep 💪 templates from Microsoft azure!The author has provided easy toFollow instructions and examples to get started on Bicep 💪.Highly recommended!
Amazon Verified review Amazon
Steven Kent Johnson Feb 10, 2022
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have been utilizing bicep since it hit general availability and was greatly impressed with the thoughtful presentation of the content. The author did a great job of walking the readers from the basics of bicep all the way through creating devops pipelines. The author provided real life examples and offers great tips and hints. Highly recommended for the novice and the IaC pro out there.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.