How to use JSON code for creating Azure Infrastructure


Let me try to walk you through your first successful deployment of infrastructure in Azure using JSON template code.

We will be using PowerShell ISE (builtin to Windows) and Visual Studio Code (download here).

First of all, open PowerShell ISE and login to your Azure Subscription and create a Resource Group:

Lets say you have an empty environment, and uses this as your templates to start a demo environment whenever needed. The PowerShell command to invoke the action in our code is:

Examples of the templatefile and parameterfile can found in my little Github repository. But what is this templatefile and parameterfile? What should you do with them?

These are the files I edit using Visual Studio Code. The template file holds all the basic information on how to create your infrastructure, but it will create it without any names or speifications. It would be like installing your infrastructure using round robin, which would be fun, but probably useless. So at the beginning of the template, there is a section called “parameters”, which collects information from your parameterfile.

Below the “parameter” section, we have the “variables” section. This is also information gathered for the template to create whatever you would like the code to create.

The paramterfile will looke like this, giving information about the storageaccountname, adminusername, adminpassword and dns name for the public IP.

The parameters should hold the customization of your deployment, but the variables could also have customization. As we see in these examples, I could move all variables that are custom for each VM into the parameters and change the parameterfile in the deployment, when I deployed the different type of VM.

If you move a value from variable to parameter, we need to add the parameter to the parameter section of the templatefile. Copy this part and paste it at the bottom of the parameters section.

Leaving the section with two “} }.” brackets under each other before the variables start.

Then go through the templatefile and locate everywhere it uses “location” and change from “[variables(‘location’)]” to “[parameters(‘location’)]”.

Now it will use the parameter to locate the value, rather then looking for a variable for the value.

After you have modified the variables and parameters, run the deployment and see that your infrastructure is created.

My next post will cover my best use of this templatefile and parameterfile, depending on the purpose, but main is often to create a demo environment.

Leave a Comment