This leads me to really needing to deconstruct a JSON template so I can really understand what’s going on. I think it’s great that we can use the Azure Quickstart Templates as resources, as well as export some templates directly from Portal configurations, but I need to break it down to really feel like I understand what I’m working with.
To relate this to real life, I started to map out a simple, yet ambitious improvement to my Imperfect Lab (the subject of prior posts). Still, this proved to be too ambitious for my “getting started with JSON” goal, so I simplified it.
Within Azure, ARM templates are awesome for doing the equivalent of “racking and stacking” in the real world. So I went small… let’s get a network deployed. A small network; the physical equivalent of a switch with a couple VLANs. Let the JSON “unboxing” begin!
A basic JSON template has this format:
The sections for $schema and resources are required. Parameters, variables and outputs are optional, depending on your needs. So let’s check out the resources I’m using and take a few notes:
- The contents of the resources section are flanked with [square brackets].
- All resources need to include the apiVersion, type and name. All the other details vary based on resource.
- All these resources in my sample use parameters to determine the properties, not variables. This means they can all be overridden with an additional “azuredeploy.parameters.json” file.
As you can see, this resources deploys a single virtual network with three subnets. Because there are no hard coded names and IP addresses, I use the parameters section to set those. (In the sample below, I’ve only shown the parameters for subnet 1, but the parameters for the other two subnets would be similar.)
- The “defaultValue” will allow the deployment to be repeatable, but can be overridden with values provided in a separate parameters file.
- The “allowedValues” section used in the location parameter is an optional example. This would drive selections from the drop down menus using the Azure portal or limit the possibilities that can be passed from a parameters file.
As none of my resources require variables or outputs, I won’t need those section in my file. The final version of the file is here.
Now to actually deploy this template, you have a few options:
- Copy and paste the code into a blank “Template Deployment” in the Azure Portal. You’ll be shown the blades for the parameters to edit or accept the default values.
- Deploy the template using PowerShell either from a local file or a web location. Not the different parameters used to determine the location and replace the placeholders with the appropriate paths. (Because I’m not using a parameters file, I’ll leave off the “-TemplateParameterURI” part.)
For a web location source (like Github) use:
For a local source (on your pc) use:
Once this template deploys, which only takes a few moments, you’ll be able to review the results in the Azure Portal.