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

eBook
₹799.99 ₹3098.99
Paperback
₹3872.99
Subscription
Free Trial
Renews at ₹800p/m

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781801813747
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. ₹800 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
₹800 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
₹4500 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 ₹400 each
Feature tick icon Exclusive print discounts
₹5000 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 ₹400 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 11,023.97
Mastering Azure Security
₹3649.99
Infrastructure as Code with Azure Bicep
₹3872.99
The Road to Azure Cost Governance
₹3500.99
Total 11,023.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.