I was writing ARM code and looking for an extension for Kubernetes at the time. During my research, I saw the Azure Resource Manager (ARM) tools, and when I started using them, they solved some of the problems I encountered while coding ARM templates. My idea was to create a simple blog entry, but after saving myself so much time, I decided to use this free time to create a full article to show TechGenix readers how to take advantage of this extension.
Installing Azure Resource Manager tools
Using Visual Studio Code, click the Extensions icon on the left side. In the Extensions Marketplace, type arm and select Azure Resource Manager (ARM) Tools from Microsoft. Click Install.
I will challenge you… even if you work with ARM templates every day, can you create an empty JSON file and create a working template and settings file? Can you do it? If yes, you have large memory capacities, 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 will create a template structure for you. If you are unsure, look at the right side and the code structure that will be added to the file.
After selecting the first entry, the result will be a template file structure ready to work with. No need to copy a sample JSON file to an article or the internet. You see, you don’t have to use your big brain to memorize every line of this standard file.
You might be wondering, this is great, but in the ARM universe we have different types of files, and depending on where we want to deploy a different structure might be needed. Don’t worry, each entry in this list will generate one of the files you might need. Here’s a quick reference:
- arms! will create a model structure
- arm!mg will create a management group template structure
- arm!s will create a subscription template structure
- arm!t will create a tenant model structure
- arms ! will create a settings file structure
Working with Parameters
We can create another file and use the same process from the previous version to create the settings file.
The next step is to start typing “” and in the list, click on “new parameter value”. Note: If the menu appears, press Ctrl+Space and the same menu will appear. Click on it.
A new parameter has been added, and we need to assign a name by replacing parameter1 and assigning a value to use in your deployment.
You can repeat the same step above for any settings 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.
Let’s go back to the template.json: you will notice that there is a space between lines 3 and 4. There is a gray line that can be activated by clicking on Change and selecting a menu with the settings file that we are going to assign to this current model.
We’ll use the parameters.json we 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 a lot of time for the developer who does not have to jump from one file to another to check the values. We can see the status at a glance.
We have this light bulb (item 3) with options to rename and review changes before committing them.
What about variables?
The same as parameters, you can invoke the functionality by typing “”, then click on new-variable and rename the new variable and value (if static) or introduce your functions to create dynamic values.
When using variables in code, as soon as you start typing variables() a list with existing variables will be displayed, choose from the list and forget about typos when referring to variables that are miles away from the variables section, more back and to recheck a variable name.
We can also check the reference of variables. We can check all references using the shortcut Shift + Alt + F12, which will bring up Find All References. A second option is to right-click the variable and click Go to References (Shift+F12), bringing a cooler view of the variables in your document. You can access the code by clicking on the references on the right side.
Creating Azure resources
Another cool feature contains all of the code to create a specific Azure resource without leaving Visual Studio Code.
It’s as simple as start typing arm- (in the resource box), and a list of all available resources will be listed. We will select Key Vault from the list as shown in the image below.
The result is code to deploy Key Vault. A good idea is that it comes with Azure Functions (item 2) to assign the location as part of the initial code. Another nice feature is that it contains references for this resource. In our case, there is a Key Vault Secret referring to this Key Vault.
If we click on the reference (item 1), it goes directly to that part of the code.
After clicking on the reference in the previous section, Visual Studio Code takes us directly to the reference. This cuts down on code back and forth time, especially in ARM templates with tons of assets.
Besides all the improvements to reduce errors and save time when coding your ARM templates, the extension provides useful information if some values are not formatted correctly. A good example is when I typed “maybe” and the validation tells me it’s a boolean.
Click on the icon shown in the lower left corner (item 1) and a list of all errors sorted by file name will be displayed.
Coding your arm model: it’s easy
The purpose of this article is to free up more time during the ARM code process. This lazy author’s personal goal is to give you more time to spend in local cafes instead of browsing your ARM templates, reviewing settings files, and many other extremely tedious tasks that can be made much easier . .