Improving your ARM template coding experience

I was writing some ARM code, and I was looking for an extension for Kubernetes at the time. During my searches, I saw the Azure Resource Manager (ARM) Tools, and when I started using it, it addressed some of the issues that I have when coding ARM Templates. My idea was to create a simple blog entry, but after saving me so much time, I decided to use that spare time to create a complete article to show TechGenix readers how to take advantage of this extension.

Installing the Azure Resource Manager Tools

Using Visual Studio Code, click on the Extensions icon located on the left side. In the extensions marketplace, type arm and select Azure Resource Manager (ARM) Tools from Microsoft. Click on Install.

ARM template

Using snippets

I will challenge you… even if you work with ARM templates every day, can you create an empty JSON file and create a workable template and parameter file? Can you do it? If yes, you have great memory skills, and please use them for something useful like counting cards and memory games 😊

Using this extension, we can open a blank JSON file and type arm! and select from the list. The first one will create a template structure for you. If you are not certain, look at the right side and the code structure that will be added to the file.

ARM template

After selecting the first entry, the result will be a template file structure ready to be worked on. No need to copy a sample JSON file in an article or on the Internet. See, no need to use that big brain of yours to remember every single line of that standard file.

ARM template

You may be wondering, that is great, but in the ARM universe, we have different types of files, and depending on where we want to deploy a different structure may be required. Don’t worry, each entry of that list will generate one of the files you may need. Here is a quick reference:

  • arm! will create a template structure
  • arm!mg will create a management group template structure
  • arm!s will create a subscription template structure
  • arm!t will create a tenant template structure
  • armp! will create a parameter file structure

Working with parameters

We can create another file and use the same process from the previous version to create the parameters file.

The next step is to start typing “” and from the list, click on “new-parameter-value.” Note: If the menu does appear, hit Ctrl+Space, and the same menu will be displayed. Click on it.

ARM template

A new parameter was added, and we need to assign a name by replacing parameter1 and assigning a value to be used in your deployment.

You can repeat the same step above for all parameters that you want to add to your deployment. Keep in mind that all parameters will be created as parameter1, which is not a problem since you will rename them.

Back to the template.json: You will notice that there is a space between lines 3 and 4. It has a gray line that is actionable by clicking on Change and selecting a menu with the parameter file we will assign to this current template.

We will use the parameters.json that we have just created, and the result can be seen in Item 1. The beauty of this feature is that the parameters created in the template file will have the values from the parameters file.

This process saves tons of time for the developer that doesn’t need to flip between files to check values. We can see the status in a single glance.

We have that lightbulb (Item 3) with options to rename and review the changes before committing them.

How about variables?

The same thing as parameters, you can invoke the feature by typing ““, then click on new-variable and rename the new variable and the value (if static) or introduce your functions to create dynamic values.

When using variables in the code, as soon as you start typing variables() a list with the existing variables will be displayed, pick from the list and forget about typos when referencing variables that are miles away from the variables section, no more back and forth to double-check a variable name.

We can also check the reference of variables. We can check all references by using the shortcut Shift + Alt + F12, which will bring up Find All References. A second option is to right-click on the variable and click on Go to References (Shift + F12), bringing a more cool view of the variables in your document. You can navigate to the code by clicking on the references on the right side.

ARM template

Creating Azure resources

Another cool feature has the entire code to build a specific Azure resource without leaving Visual Studio Code.

It is simple as start typing arm- (in the resources area), and a list of all resources available will be listed. We will be selecting Key Vault from the list as depicted in the image below.

The result is a code to deploy Key Vault. A nice touch is that it comes with Azure Functions (Item 2) to assign the location as part of the initial code. Another cool feature is that it has references for this resource. In our case, there is a Key Vault Secret referencing this Key Vault.

If we click on the reference (Item 1), it goes straight to that portion of the code.

After clicking on the reference in the previous section, the Visual Studio Code moves us directly to the reference. That reduces the time going back and forth on the code, especially in ARM templates with tons of resources.

Validating errors

Besides all improvements to reduce error and save time when coding your ARM templates, the extension provides useful information if some values are not formatted well. A good example is when I typed “maybe,” and the validation informs me that it is a Boolean.

Click on the icon displayed on the bottom left corner (Item 1), and a list of all errors categorized by file name will be displayed.

ARM template

Coding your arm template: Easy does it

The goal of this article is to free up more of your time during the ARM code process. The personal goal of this lazy author is to give you more time to spend in the local coffee shops instead of going up and down over your ARM templates, reviewing parameter files, and many of the other grindingly tedious tasks that can be made so much easier.

Leave a Comment

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top