Get the most from your time using ARM Templates!
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.
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
- Download and install Microsoft Visual Studio Code. This is not only useful for creating ARM Templates, but for anything you need syntax highlighting for.
- 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:
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:
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!
- Go to portal.azure.com and sign in with your relevant credentials
- Search for ‘Templates’ in the search bar and click the option as shown below
3. Give it a name and description, then click OK
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.
7. Click your resource, then click “Deploy”
8. Fill in the blanks and click purchase! (Be aware, you will be billed for this if you proceed!)