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

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
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 AU $24.99/month. Cancel anytime