Today is Azure RM template structure day! Well… it should be.

What is JSON?

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

I’m glad I can make myself clear to robots!

talk like a robot when using azure rm templates

Structure of ARM templates

Parameters

According to Wikipedia, a parameter in computing is defined as “a reference or value that is passed to a function, procedure, subroutine, command, or program”.

So, we can use parameters to deploy custom resources. If we do not create parameters in our template, the deployed resources would always turn out the same. Boring, right?

Luckily, we can use these parameters to bring a bit of flair in our deployments. Let’s say we would like to create a virtual machine template. Of course, we would like to customize the name of the new machine.

We declare a parameter “virtualMachineName“, type “String” in our template.

"parameters": {
    "virtualMachineName": {
        "type": "String"
    }
}

This virtualMachineName parameter we use when deploying our template. Azure CLI, PowerShell or uploading our template to Azure are all options. Next, we will be prompted to complete our defined parameters.

Now, we choose a beautiful name for our machine. This will be written to our parameter. Whenever the parameter is used in the body of the template, we will see our virtualMachineName dynamically added.
“Beautiful name” –> Parameter “virtualMachineName” –> Script –> VM with name “Beautiful name”

Cool!

Variables

Variables are containers for storing data.

For example, you would like to provision some machines hosting a specific application. These machines all need a local administrator account. Let’s store that “localAdmin” account name in a variable.

"variables": { 
    "localAdmin": "Gandalf"
}

Recommendations from Microsoft:

  • Use variables for values that you need to use more than once in a template. If a value is used only once, a hard-coded value makes your template easier to read.
  • You cannot use the reference function in the variables section of the template. The reference function derives its value from the resource’s runtime state. However, variables are resolved during the initial parsing of the template. Construct values that need the reference function directly in the resources or outputs section of the template.
  • Include variables for resource names that must be unique.

Resources

This one is self-explanatory. In the “Resources” section of we can define resources.

Easy as pie… ow… nevermind. We have some things to keep in mind:

DO IT YOURSELF:

  • Export a template.
  • Check out the parameters, variables and resources sections.
  • Find some examples of things you would like to customize.

Quite some reading material above. Next time we will do some practical stuff. I promise.


2 Comments

How to use Azure RM templates series - Introduction | Yvez · 27/05/2018 at 11:55

[…] Structure of an ARM template. […]

How to use Azure RM templates series – Where to get an ARM template? | Yvez · 27/05/2018 at 11:56

[…] Next time we will have a look at adjusting and deploying some of our templates. A bit of a deeper dive in the structure of JSON. […]

Leave a Reply

Your email address will not be published. Required fields are marked *