Authoring ARM Templates

Introduction

This self-paced enablement session will run through a sequence of bite-sized labs that build on each other.

Each lab will always include links to the JSON templates at the start and end so that you may compare your own files and highlight any differences.

It is up to you how far through the labs you need to go. The labs go through to a level of detail and complexity and leverage a number of the features within the Azure Resource Manager (ARM) templates that provide the power required for more complicated enterprise Infrastructure as Code deployments.

However the advice would always be to keep it as simple as possible and maximise supportability. Therefore the recommendation is to stop at the earliest point where you can meet the business requirements.

The comments section has been enabled and feedback is always welcome.

The short URL to get back to this page is:

aka.ms/citadel/arm

Pre-requisites

Azure subscription

You will need a working Azure subscription.

Test that the subscription is active by logging onto the portal and creating an resource group.

Visual Studio Code plus extensions

For the labs we will be using Visual Studio Code, configured as per the VS Code prereqs page. Please follow all of those configuration steps to make sure you are ready to begin the labs.

You will need to add in the following extensions to vscode for the ARM workshop:

Module Name Author Extension Identifier
Azure Account Microsoft ms-vscode.azure-account
Azure Resource Manager Tools Microsoft msazurermtools.azurerm-vscode-tools
JSON Tools Erik Lynd eriklynd.json-tools

Extensions Figure 1: Extensions in vscode

Use CTRL+SHIFT+X to open the extensions sidebar. You can search and install the extensions from within there. Once you have installed them all then click on one of the Reload buttons.

ARM Snippets

Finally, add the snippets for Azure Resource Manager.

  1. Browse to the snippets file and copy the contents
    • Click on the file contents to get focus
    • Type CTRL+A then CTRL+C
  2. In VS Code, go to File -> Preferences -> User Snippets -> JSON
  3. Paste in the contents before the last curly brace
  4. Ensure the JSON file has no syntax errors and save

💬 Note. Do not install the third party Azure Resource Manager Snippets extension available in the gallery. This only has a subset of the snippets that you will find in Sam Cogan’s GitHub repository.

If you have done this correctly then the following test should work:

  1. Create a new file (CTRL+N)
  2. Save it as test.json (CTRL+S)
  3. Click in the file to get focus
  4. Type ‘arm’ and you should see the Intellisense list appear
  5. Hit ENTER or TAB when arm! is highlighted
  6. Save the file (CTRL+S)

Figure 2: Adding JSON snippets into vscode and testing

Feel free to delete the resulting test.json file.

GitHub Account

We’ll be using a GitHub account from the start of the workshop so that you can keep your templates in a repository, synced up from your laptop using vscode. This will be more important as you get to the later labs that will make use of files in the repoistory using the https addressing.

If you do not already have a GitHub account then go to https://github.com/ and create one. Don’t forget to check for the email to verify your address.

Follow the instructions in the https://github.com/azurecitadel/arm-workshop readme file. You will fork and clone the sample area so that you are ready to start the following labs.

Index

Lab Section Description
  Azure Resource Manager A short theory session on Azure Resource
  ARM Templates Template structure overview, options for creating and deploying
1 First Template Create a simple template, factor parameters, and deploy using the CLIs
2 Sources of Resources Different sources of templates
3 References and Secrets Functions, references, and how to handle secrets
4 Conditional Resources Using conditions to selectively deploy resources
5 Using Copy Use the copy property to create multiple resources
6 Objects and Arrays More complex parameters, variables and outputs
7 Nesting Templates Nesting templates inline and with linked templates