top of page

ARM templates

This page will explain what, how and why to use ARM templates building your projects.

Azure Resource Management (ARM) is the code that builds and configure artifacts in Azure.  In the following tutorial I am going to show you how to create and deploy a Storage Account using ARM.

 

If you use Azure Portal and create an artifact you can see the ARM used to create the artifact by selecting Export Template. What you see is JSON script with hard coded values and you can of course use this template as a base for a new template or find ways to add new features for your own design here.

Why bother creating your own templates?  

  • It’s a nice way of handling source code changes in a repository.

  • You can make better deploy methods.

  • You can reuse code and don't miss important variables

To create ARM templates most things has already been done and published to the public at GitHub on QuickStart. The ARMs are deployed to a resource group where you keep all resources to a specific artifact.

To develop ARMs, I usually use Visual Studio Code and some extensions that could help me out:

Read more about them​ under the links.

Example below is based on a storage account create

ARMs are built on JSON and you start with a schema 

{

"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#"

}

Most ARMs have some parameters in the top of the script. This param lets you select type of storage account. The parameter type is string etc. the square brackets design an array of in this case selectable values. This parameter can be used as input values in a config file described later where the default value could be replaced.  

"parameters": {

"storageAccountType": {

"type": "string",

"defaultValue": "Standard_LRS",

"allowedValues": [

"Premium_LRS",

"Premium_ZRS",

"Standard_GRS",

"Standard_GZRS",

"Standard_LRS",

"Standard_RAGRS",

"Standard_RAGZRS",

"Standard_ZRS"

],

"metadata": {

"description": "Storage Account type"

}

}

The variable selected in from the parameters are then used in the resource  

"resources": [

{

"type": "Microsoft.Storage/storageAccounts",

"apiVersion": "2021-06-01",

"name": "[parameters('storageAccountName')]",

"location": "[parameters('location')]",

"sku": {

"name": "[parameters('storageAccountType')]"

},

"kind": "StorageV2",

"properties": {}

}

]

When the ARM is finished you should create a parameter file. This is simply done by right clicking on the canvas and select "Select/Create Parameter File... " and a select "new", "all parameters" and you will be prompted with a suitable file name.

Example:

{

    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",

    "contentVersion": "1.0.0.0",

    "parameters": {

        "storageAccountName": {

            "value": "xxx"

        },

        "location": {

            "value": "West Europe"

        },

        "storageAccountType": {

            "value": [

"Premium_LRS",

"Premium_ZRS",

"Standard_GRS",

"Standard_GZRS",

"Standard_LRS",

"Standard_RAGRS",

"Standard_RAGZRS",

"Standard_ZRS"

            ]

        },

}

bottom of page