How to create resources using an ARM template locally?

code projected over woman
Reading Time: 3 minutes
ARM template

Introduction

ARM template is used to create resources as per the Azure Resource Manager. The template file is written in JSON. And we can deploy it using the azure portal or locally using Azure CLI or Azure PowerShell. Here, in this blog, we will deploy the template using the local method.

Prerequisite

  1. Understanding of Azure Services
  2. Linux OS
  3. Visual Studio Code ( optional )

Preparations for the ARM template

1. VS Code Extension

If you have visual studio code installed on your system locally, you can install the following extension for the ARM template: Azure Resource Manager (ARM) tools. This provides snippets and auto-completion for ARM templates.

2. Azure CLI setup

We need to install Azure CLI on our local system. And so, we follow the steps defined here. These are steps for Ubuntu but you may change them as per your Operating System.

Then do login on to your Azure account using Azure CLI

az login browser
az login cli

Now configure default values to make it easy for deployment, like location and resource group.

az default value

Creating the ARM template

  1. Create an azuredeploy.json file.
  2. Open in Visual studio code.
  3. Type arm and select the first option. The ARM tools extension creates a basic snippet.
  4. Similarly, click inside resources and type storage and select the first option. We now have the storage account snippet.
  5. As you can see inside the snippet, the location is already parameterized.
  6. We will parameterize the name and storage type option.
    • We add parameters inside parameters. Click inside the square brackets and type par and press “ENTER
    • After that, we modify the snippets as shown in the diagram.
  7. And then we modify the resource values to take the input per the parameters defined.
  8. If we want, we can add output to define what to print after the successful deployment.
arm snippet
arm template snippet

Adding parameters

Arm template parameters
parameters snippet

Modify them as per use.

parameter defined

Modify values in resources.

parameters input

Define the outputs.

output ARM template

Running the ARM Template

We run the following set of commands.

running template

And when it says running on Azure CLI, we move to the azure portal to see if it is deploying: Home —> Resource groups —> Resource Group selected —> deployments

template status portal

Once the deployment completes, it shows completed. Click on the deployment name and go to the resource.

deployed resource
resource created

Similarly, the Azure CLI gives output.

deployment output

Conclusion

The ARM template is similar to AWS cloud formation and other IaC automation available. This was for learning you can modify and play with source code from Knoldus TechHub. Keep Learning!

References

Written by 

Explorer of new technologies: from DevOps to Web 3

Leave a Reply