Infrastructure as Code | 4 Min Read

Azure Resource Manager (ARM) - Infrastructure as Code on Azure

Infrastructure as Code(IaC), as the name suggests, is related to the codification of a given infrastructure. So in this blog, we will be going through what is IaC, what is the need for IaC, and when it comes to Azure, what do we have in store to achieve the IaC process.


Infrastructure as code is a provisioning & managing infrastructure like VM/EC2, VPC with code/configuration files. It allows us to treat infrastructure configuration and provisioning just like we handle application code, which will enable us to version code in any popular SCM to take advantage of CI/CD pipelines easily.

Need of IaC

Previously, infrastructure management & configuration was done manually. Each environment has its unique configuration, which was configured manually, and that led to several problems like:
Cost as you have to hire many professionals for management and maintenance of infrastructure.
Scaling as a manual configuration of infrastructure tasks is time-consuming, which often tends to make you struggle to meet spike on request.
Inconsistency because the manual configuration of infrastructure is error-prone. When several people do manual configurations, errors are unavoidable.
Whereas IaC is idempotent, which ensures the same deployment results in a given environment.

Why IaC on Azure?

Globally, 90% of fortune 500 have shown their belief in Azure to drive their business. It has various services in all aspects to resolve business problems from storage to AI/ML to IAM over a single platform.
With IaC, Azure resources management gets way easier through configuration files with consistency, which ensures fewer errors & provides preciseness.
The two important methods to implement IaC on Azure are:
ARM Templates
Terraform

IaC on Azure using ARM

To implement IaC on Azure, use Azure Resource Manager templates (ARM templates). It is a file written in json based on declarative syntax, which lets you define the state of the infrastructure you want to deploy without writing a sequence of commands to achieve that state.
In the ARM template, resources & their properties are specified for deployment. It is a native option for Azure.

  • Features of Azure Resource Manager(ARM)

ARM is compact with various features, which makes it an ideal choice for the IaC tool. Here are a few of them.

Declarative syntax

It allows you to define the state of the infrastructure you want to deploy without mentioning steps/commands to achieve that state.

Consistent Results

Every time you deploy, resources get deployed consistently with the same result over a given environment as Templates are idempotent.

Orchestration

Resource managers ensure the deployment of interdependent resources so they may get deployed in the correct order, which makes work easier without getting into the complexity of ordering operations.

Modular files

It allows you to break your desired infrastructure into smaller reusable components, which can also be nested in other templates.

Extensibility

You may add PowerShell/Bash script in a template. It ensures that the users get extended ability to set up the required resources.
& many more features like built-in validation to ensure the success of deployment & tracked deployments to get information about deployment history & other information related to deployments.

How ARM works?

Azure Resource Manager service enables centralizing the resource management, security & deployment via tags to enable users to create, modify & delete resources.
All requests from APIs, Azure tools or SDKs, and Resource Manager firstly get authenticated & authorized, then these requests are sent to the Azure service, which performs the requested action. As all requests are handled via the same API, you get consistent results.

Benefits of IaC on ARM

Choosing ARM for IaC on Azure enables you with:
Managing infrastructure through declarative templates (ARM Templates) rather than scripts.
It allows you to manage, monitor & deploy all your solutions' resources as a group, rather than handling resources individually.
It assures you of the consistent state over a given environment throughout the development lifecycle.
You can define dependencies between resources for getting deployed in the correct order & for faster deployment, and ARM runs independent jobs parallelly.
Allows you to implement access control to all services as Azure RBAC is integrated into the management platform.
Attach tags to resources to logically organize resources in subscription & get clarity on the organisation's billing by viewing costs for a group of resources of the same tag.

ARM Best Practices

Template limits

Limit the size of your template to 4 MB. This applies to the template's final state after expansion with iterative resources & values for variables & parameters. Also, each parameter file should be limited to 64 KB.
With further limitations:
256 parameters
256 variables
800 resources (including copy count)
64 output values
24,576 characters in a template expression
Some of the limits can be exceeded using a nested template.

Resource groups

Create a resource group in the same region as resources as it contains metadata of resources.
If the resource group deployed in another region is temporarily unavailable, you won't be able to update resources in the resource group as metadata is unavailable.

API version

Set the hard-coded value of API version property for the resource type. While creating a new template, we recommend you use the latest API version for a resource type to determine available values. When your template works as expected, the recommendation is to use the same API version, so you don't have to worry about the changes.

Use test toolkit

It's a script that ensures best practices are being followed in a given template. If the template isn't compatible with the best practices, it returns a list of warnings and suggested changes.

Terraform

After ARM templates, the second most popular method to implement and use IaC principles on Azure is Terraform. It is the most popular and open-source tool provided by HashiCorp for infrastructure automation. It creates IaC for cloud providers like Azure, AWS, GCP with the same workflow. It helps in configuring, provisioning, and managing the infrastructure as code as it allows codification of infrastructure like VM, storage & other Azure resources through its configuration files. It enables developers to manage infrastructure with consistent tooling across various cloud platforms.
To know more about Terraform and its working, you can visit our next blog post, i.e., Everything there is to know about Terraform.

Conclusion

IaC is a process of representation and management of the infrastructure in the form of code that tends to consistent & efficacy. Additionally, Azure is one of the leading & reliable public CSP for IaC implementation due to its native service ARM template & its compatibility with open source tools like terraform.

Subscription

Fresh news directly to your mailbox