Get the most from your time using ARM Templates!

Nathan Magyar
4 min readDec 3, 2020

--

A blank, white billboard on the side of a deserted highway with some dry rocks and sun damaged grass.
Your template is your blank canvas. Now fill it in and deploy those resources!

There are many reasons an ARM (Azure Resource Manager) template is useful. For me, it’s about producing Repeatable Results. Business is driven by producing consistent, repeatable results. Where would we be without templates? Take a look around you, the chair your sitting on right now was likely created using die casts, the glass you drink from made using molds — everything is made using some kind of template. That’s what an ARM template is. It’s Azure’s very own answer to the die cast.

So what can we actually do with these templates? Looking at the Azure Quickstart Templates is a sure fire way to see just how limitless the potential of these are. For me, I’ve used them recently to simplify the deployment of new DNS Zones. Here’s what the deployment for that looks like.

A screenshot of the Azure Template deployment screen. Showing the Azure Portal and how the ARM Template is used.
ARM Templates make repeatable deployment of resources super simple.

Using this template, I’m able to quickly create a DNS Zone, add it to a Subscription, within the relevant Resource Group and add two tags (Company_Rec ID/Customer) that we use for billing purposes. This ensures that all of our DNS Zones are created equal, no matter who might need to perform the job — it helps mitigate that degree of human error. What’s under the hood? Just 38 lines of simple JSON.

I’m sure you can think of a hundred different ways this might be useful to you or your organisation, so let’s get into the how (I promise you, it’s not that hard!) I’ve kept mine very simple, for a more detailed tutorial I recommend following this Microsoft Doc.

TUTORIAL — Create an Azure DNS Zone with two custom tags

  1. Download and install Microsoft Visual Studio Code. This is not only useful for creating ARM Templates, but for anything you need syntax highlighting for.
  2. Create a new file and save it as a JSON. Then, copy and paste the following into Visual Studio Code.

3. Add your resources into your JSON, simply copy the below and highlight line 4 in your file (this line should contain “resources”: []), then paste over the top.

To break down the code block below, we’ve:

  • Specified the type of resource (dnsZones)
  • The API Version (2016–04–01)
  • The name of the resource (this is going to utilise the parameter name we specify in step four)
  • The location (Global)
  • The tags, which both refer to parameters defined in step four.
  • We have not specified any dependencies or properties (for more information on the syntax of an ARM template check this doc out)

At this point, your file should look like this:

A screenshot of my JSON ARM (Azure Resource Manager) template so far. This screenshot was taken in Visual Studio Code.

4. Add in your parameters. For mine, I’ve chosen to add a parameter for the DNS Zone Name as well as two tags (Company_RecID/Customer) The description we’ve specified will become a tooltip when you deploy the template via the Azure Portal, so be sure to make yours something helpful. Go to the line that your “contentVersion” is defined on, then at the end of the line press enter and copy and paste the below on the new line (between “contentVersion” and “resources”)

Viola! We’re finished — if you’ve followed this correctly, you should be left with something like the below:

Another screenshot of Visual Studio Code showing my Azure Resource Manager template in the current state.

Hint: If you see anything as a different colour to what I’ve shown above, check:

  • That the file extension is .json
  • That your quotation marks (“), curly braces ({}), commas (,), square brackets ([]), colons (:) and apostrophes (‘) are in the correct positions. JSON is not whitespace sensitive, so don’t worry if your whitespace isn’t aligned like my example shown above.

Deploying your Template!
You’ve done the ‘hard’ yards, now time to put that die cast to work!

  1. Go to portal.azure.com and sign in with your relevant credentials
  2. Search for ‘Templates’ in the search bar and click the option as shown below
Microsoft Azure Portal, showing the search bar searching for templates.

3. Give it a name and description, then click OK

Microsoft Azure Portal showing a name and description being set (deployAzureDnsZone / Deploys an Azure DNS Zone)

4. Copy and paste your code that you created in Visual Studio and click OK

5. Click OK, then click Add

6. Check the bell icon in the top right corner, once completed — you should see something like the below. Click the “Template saved” hyperlink to follow it to your newly created resource.

The Azure Portal notifications bell showing a template being saved in the activity log.

7. Click your resource, then click “Deploy”

The Azure Portal showing the deploy button on the newly created ARM (Azure Resource Manager) template

8. Fill in the blanks and click purchase! (Be aware, you will be billed for this if you proceed!)

Azure Portal template deployment / purchase screen

--

--

Nathan Magyar
Nathan Magyar

Written by Nathan Magyar

A Systems Engineer with a passion for all things PowerShell based in Melbourne, Australia. https://www.linkedin.com/in/nathanmagyar/

No responses yet