In my previous article, Azure App Service: Create Web Apps Using Resource Manager Template In Visual Studio, we created a basic Azure App Service web app using Quick Start ARM templates available in Visual Studio. We didn’t go through the content of the ARM template.
Azure ARM templates allow us to achieve “Infrastructure as a Code”. Yes, you can create/deploy your infrastructure using Code.
What is ARM Template?
ARM template is a .JSON file and by using it, you can instruct ARM (Azure Resource Manager) to provide you the required infrastructure services in a declarative manner.
Let’s take a blank template now and go through the JSON file in order to understand its elements.
Open Visual Studio (I’m using Visual Studio 2013) and create a New Project -> Select Cloud -> Azure Resource Group.
Once you click OK in the previous step, Visual Studio displays all the available templates as shown below.
Now, select “Blank Template” and click “OK”.
Visual Studio will create a couple of files which are described in my previous article.
The details are shown below about the elements of the. JSON file (ARM template).
|$schema||Yes||Location of the JSON schema file that describes the template language. You should use the same for all the template files that you author.The JSON files use a schema which is referenced at the top of each file. You can download the schema and analyze it if you want to understand it better. The schema defines what elements are allowed, the types and formats of fields, the possible values of enumerated values, and so on.|
|contentVersion||Yes||Version of the template|
|Parameters||No||Instead of hard coding the values in the template file, you can provide the facility of passing them as parameters. Just like passing values to functions by external resources who would like to utilize the template.|
|variable||No||These are internal to the template. External resources will not have access to these variable. These are much like variables within the functions.|
|Resources||Yes||Here comes the important node. This is where we specify the resources which you would like to create. You can even have nested resources. You can specify whether you want to deploy “Complete” or “Incremental” resources.|
|output||No||If you want to return any output value to the caller.|
Please note that it is not mandatory to use Visual Studio to create / author the. JSON file. You can use any of your favorite editors to author your ARM templates. I’m using Visual Studio as it is very easy to author the ARM template using Visual Studio features like Intellisense, JSON Outline tools etc. which we will be looking at in our future articles.
A few advantages of using ARM templates are shown below.
- You can declaratively define your infrastructure with the help of the ARM templates.
- You can reuse these templates to deploy the resources in multiple environments. For example, if you author an ARM template to create a WebApp + SQL for your Dev environment, you can utilize the same for your Staging as well by making very little changes to the parameter list.
For more details about the ARM, template please refer Official documentation.