Deploying and configuring cloud infrastructure is often carried out using infrastructure as code (IaC). It is essential for cloud professionals to master. Microsoft Azure uses Azure Resource Manager (ARM) templates and the more recent Bicep files. These tools allow Azure administrators to manage their infrastructure efficiently. Mastery of these concepts is also crucial for success in the AZ-104 exam.

Introduction to ARM Templates and Bicep Files

First, let’s consider ARM templates. These JSON files are used to define infrastructure and configuration for resources in Microsoft Azure. With ARM templates, you can deploy and configure your resources effectively and consistently, which is extremely important.

Protect Your Data with BDRSuite

Cost-Effective Backup Solution for VMs, Servers, Endpoints, Cloud VMs & SaaS applications. Supports On-Premise, Remote, Hybrid and Cloud Backup, including Disaster Recovery, Ransomware Defense & more!

Bicep is a newer domain-specific language (DSL) that can also deploy Azure resources. It offers a more human-readable language syntax than JSON. You can think of languages like Terraform’s HCL language that are intuitive and easy to read. Bicep has that same intuitive look and feel to the language.

Why Use ARM Templates and Bicep Files?

What are some of the major reasons to consider using ARM Templates and Bicep files in Microsoft Azure? Note the following benefits to consider:

  • Automation: Deploy resources automatically and as many times as needed without manual actions
  • Consistency: You can make sure deployments happen exactly the same way across multiple environments or tenants
  • Versioning: Since infrastructure as code can be committed to code repositories, you can track changes in your infrastructure code over time

Key Components of ARM Templates

Let’s consider key components of ARM templates and the important bits to remember. An ARM template consists of several key sections:

Download Banner
  • schema: This section specifies the location of the JSON schema file that describes the version of the template language
  • contentVersion: Notes the version of the template (e.g., “1.0.0.0”)
  • parameters: You can define values to be passed during deployment to customize resource configuration
  • variables: Values that can be reused in the template
  • resources: The Azure resources to be deployed
  • outputs: These output information about the deployed resources from the ARM template

Example of an ARM Template Structure

Let’s look at a sample ARM template. This will help get a feel for how these are written, including their components and what they look like. The code below defines and deploys an Azure Storage Account.

{
“$schema”: “https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#”,
“contentVersion”: “1.0.0.0”,
“parameters”: {
“storageAccountType”: {
“type”: “string”,
“defaultValue”: “Standard_LRS”,
“allowedValues”: [
“Standard_LRS”,
“Standard_GRS”,
“Standard_ZRS”,
“Premium_LRS”
],
“metadata”: {
“description”: “Storage Account type”
}
}
},
“variables”: {
“storageAccountName”: “[concat(‘storage’, uniqueString(resourceGroup().id))]”
},
“resources”: [
{
“type”: “Microsoft.Storage/storageAccounts”,
“apiVersion”: “2019-04-01”,
“name”: “[variables(‘storageAccountName’)]”,
“location”: “[resourceGroup().location]”,
“sku”: {
“name”: “[parameters(‘storageAccountType’)]”
},
“kind”: “StorageV2”,
“properties”: {}
}
],
“outputs”: {
“storageAccountName”: {
“type”: “string”,
“value”: “[variables(‘storageAccountName’)]”
}
}
}

Understanding Bicep Syntax

The Bicep language syntax provides a much simpler approach to the JSON syntax found in ARM templates. The code below performs the same operations as the JSON code in the Azure template above. It defines and creates a storage account. Note the much shorter and easier to read code in the example:

param storageAccountType string = ‘Standard_LRS’

var storageAccountName = ‘storage${uniqueString(resourceGroup().id)}’

resource storageAccount ‘Microsoft.Storage/storageAccounts@2019-04-01’ = {
name: storageAccountName
location: resourceGroup().location
sku: {
name: storageAccountType
}
kind: ‘StorageV2’
properties: {}
}
output storageAccountName string = storageAccount.name

Practical Examples of ARM and Bicep

A common task that is generally automated is deploying a virtual network in Microsoft Azure. Creating virtual networks is part of the foundation usually created by infrastructure as code before other resources can be deployed.

Below is an example of deploying a virtual network using an ARM template:

{
“$schema”: “https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#”,
“contentVersion”: “1.0.0.0”,
“parameters”: {
“vnetName”: {
“type”: “string”,
“defaultValue”: “myVnet”
},
“addressPrefix”: {
“type”: “string”,
“defaultValue”: “10.0.0.0/16”
}
},
“resources”: [
{
“type”: “Microsoft.Network/virtualNetworks”,
“apiVersion”: “2019-04-01”,
“name”: “[parameters(‘vnetName’)]”,
“location”: “[resourceGroup().location]”,
“properties”: {
“addressSpace”: {
“addressPrefixes”: [
“[parameters(‘addressPrefix’)]”
]
}
}
}
]
}

Now let’s consider creating a virtual network in Azure using Bicep:

param vnetName string = ‘myVnet’
param addressPrefix string = ‘10.0.0.0/16’

resource vnet ‘Microsoft.Network/virtualNetworks@2019-04-01’ = {
name: vnetName
location: resourceGroup().location
properties: {
addressSpace: {
addressPrefixes: [addressPrefix]
}
}
}

Best Practices for Using ARM Templates and Bicep Files

There are several best practices to keep in mind when using ARM Templates and Bicep files. Note the following:

  • Make code modular: Break down complex templates into smaller, reusable components
  • Use parameters: Use parameters to customize deployments without modifying the template
  • Validate code: Validate templates before deployment to catch errors
  • Use Version Control: Use version control systems (e.g., Git) to manage changes
  • Document your code: Insert comments in your code and provide documentation to help others understand changes and help maintain the code

Common Exam Scenarios and Questions

Consider the following examples of exam scenarios and questions.

  1. Scenario 1: You need to deploy a storage account with specific configurations. The exam may present you with an ARM template or a Bicep file and ask you to identify the required parameters or resources
  2. Scenario 2: You might be given a faulty ARM template or Bicep file and asked to debug and correct the syntax or logic
  3. Scenario 3: Questions may involve interpreting the outputs of a deployment to ensure the correct resources have been created

Wrapping up

In Microsoft Azure, understanding how to interpret ARM templates and Bicep files are core skills you must be familiar with for the AZ-104 exam. Both of these IaC languages streamline deployments and configuration of resources. They help make sure infrastructure is deployed in a consistent and repeatable way. Be familiar with the syntax and structure of the JSON ARM templates and Bicep files. Not only will this help with the exam, but it will also be a required competency in production environments.

Related Posts:

Microsoft Azure Administrator: AZ-104: Configure Blob Versioning – Part 36

Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.

Rate this post