Day 11 – Azure Resource Manager Templates (Transcript)
Today is Day 11 of the Azure Zero to Hero series.
In this session, we will explore Azure Resource Manager and Azure Resource Manager
templates. We will use some examples and learn how to write those examples to create
resources such as storage accounts, virtual machines, and other Azure resources.
From an interview point of view, we will also compare Azure Resource Manager templates
with other options such as Bicep, Azure CLI, and Terraform. This comparison will help you
understand when to choose Azure Resource Manager templates and when to use other
tools.
Let us start by understanding what Azure Resource Manager is and why we use Azure
Resource Manager templates.
Azure Resource Manager is responsible for creating resources in Microsoft Azure. As a user,
there are multiple services available to create resources in Azure. You can use the Azure
Portal, Azure CLI, Azure Resource Manager templates, Bicep, or SDKs.
Regardless of the method you use, all these services communicate with Azure Resource
Manager. Azure Resource Manager is the layer that finally creates the resources on the
Azure platform.
Azure Resource Manager exposes APIs, and all tools such as the portal, CLI, templates,
Bicep, and SDKs interact with these APIs.
The question is why Azure needs this layer.
The answer is standardization.
If Azure Resource Manager did not exist, each service such as the portal, CLI, or SDK could
enforce different validation rules. For example, one service might allow a resource name of
a certain length, while another service might enforce a different rule. This would result in a
poor user experience.
Azure Resource Manager ensures that validation rules and behavior are consistent
regardless of the tool used to create resources. This provides a standardized experience
across all Azure services.
Now let us understand what Azure Resource Manager templates are.
Azure Resource Manager templates are a way to define Azure resources using JSON. These
templates are submitted to Azure Resource Manager, which then creates the resources.
Azure Resource Manager templates are just another way, similar to the portal or CLI, to
request resource creation.
Now let us understand how to write Azure Resource Manager templates.
We will use Visual Studio Code to write these templates. Once the Azure Resource Manager
Tools extension is installed, it provides schema validation and templates to simplify writing
JSON.
We will start by creating a simple Azure Resource Manager template to create a storage
account.
When creating a template, the key sections include schema, contentVersion, parameters,
variables, resources, and outputs.
The resources section defines what resources will be created.
Using the extension, we can generate boilerplate templates for resources such as storage
accounts and virtual machines. This reduces the complexity of writing templates from
scratch.
Once the template is written, the next step is deployment.
Templates can be deployed using Azure CLI. The deployment process sends the template to
Azure Resource Manager, which validates and creates the resources.
A resource group must exist before deploying a template. Resources defined in the template
are created inside the specified resource group.
After deployment, the created resources can be viewed in the Azure Portal under the
resource group.
Now let us understand the important sections of an Azure Resource Manager template.
The schema section validates the structure of the template. It ensures that the template
follows the correct format and rules.
The contentVersion defines the version of the template.
Parameters allow you to make templates reusable. Instead of hardcoding values,
parameters allow users to provide input values during deployment.
Variables are used to store values that are reused multiple times within the template.
Resources define the actual Azure resources to be created.
Outputs allow you to return values after deployment, such as resource names or IP
addresses.
Functions are used when you want to add logic or generate dynamic values within the
template, such as creating unique resource names.
Now let us discuss creating a virtual machine using Azure Resource Manager templates.
The virtual machine template includes multiple dependent resources such as storage
accounts, public IP addresses, network security groups, virtual networks, and network
interfaces.
All these resources are created together because the virtual machine depends on them.
Once the template is deployed successfully, all related resources appear under the resource
group.
After practicing deployments, it is important to delete the resource group to avoid
unnecessary costs.
Now let us compare Azure Resource Manager templates with other tools.
Azure Resource Manager templates are widely used in Azure-focused organizations. Many
existing Azure environments still rely heavily on ARM templates.
Bicep is a newer abstraction over ARM templates. Bicep code is eventually converted into
ARM templates before deployment. While Bicep is recommended by Microsoft, many
organizations have not fully migrated yet.
Terraform is a popular tool used across multiple cloud providers. It is a good option if you
are working in a multi-cloud environment or transitioning between cloud platforms.
Azure CLI is useful for quick actions and scripting but is not ideal for managing large,
repeatable infrastructure setups.
As a DevOps engineer, it is not necessary to learn all tools at once. Start with one, gain
experience, and then expand.
If your organization is heavily invested in Azure, learning Azure Resource Manager
templates or Terraform is recommended.
This concludes Day 11.
Practice creating storage accounts and virtual machines using Azure Resource Manager
templates. With experience, writing and understanding templates will become easier.