
Creating your own ARM template (for developers)
To create an ARM template, perform the following steps:
- Open your Visual Studio. First, click on the File button, then click on New and the Project... link, as shown in the following screenshot:

- The selection dialog opens with the available project templates. The required template, Azure Resource Group, can be found in the Cloud area:

- If everything is clear, specify a project name, for example, ARMTemplateDemo, and press the OK button.
- Now, another selection dialog opens, this time with a list of available Azure templates. For our demo, we need Blank Template. Select the entry and press the OK button:

- Wait briefly until the project has been loaded. You should now see the following screen:

The project consists of the following three artifacts:
-
- azuredeploy.json: This is the template for your own ARM template
- azuredeploy.parameters.json: This is used as a store for all the required parameter values
- Deploy.AzureResourceGroup.ps1: This is a PowerShell script that will help you to perform the final deployment
Let's have a deeper look:
I would like to start with the azuredeploy.json file. Please click on the corresponding entry in the Solution Explorer. Now, you should see the following screen:

In the middle area of the Visual Studio IDE (the editor window) the following code block is now given:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01- 01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": {}, "variables": {}, "resources": [], "outputs": {} }
This code is the simplest form of an ARM template, but I should like to point out that, in this form, the template is not valid and cannot be executed.
Here is the reason: some of these fields are required and others are optional. The following table shows whether a field should be filled in:

As you can see, the $schema, contentVersion, and resources fields need to be filled in. For the $schema and contentVersion fields, you can continue to use the pre-enclosed values, so you must add at least one resource.
Now, let's add a resource. Once again, I chose a storage account as the resource type. The relevant section in the azuredeploy.json file looks like this:
"resources": [ { "type": "Microsoft.Storage/storageAccounts", "name": "[parameters('storageAccountName')]", "apiVersion": "2015-06-15", "location": "[resourceGroup().location]", "properties": {
"accountType": "Standard_LRS" } } ]
There's one thing I need to point out: the use of parameters is not necessary, but without parameters, your template would always deploy the same resources with the same names, locations, and properties.
In order to avoid this situation, in the presented code segment, a parameter for the resource name is used.
For the parameters, we have to provide the corresponding definition. The relevant section in the azuredeploy.json file looks like this:
"parameters": { "storageAccountName": { "type": "string", "metadata": { "description": "Storage Account Name" } } }
The template is now ready, valid, and executable. The complete code for our azuredeploy.json sample file looks like this:
{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "storageAccountName": { "type": "string", "metadata": { "description": "Storage Account Name" } } }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "name": "[parameters('storageAccountName')]", "apiVersion": "2015-06-15", "location": "[resourceGroup().location]", "properties": { "accountType": "Standard_LRS" } } ] }
The next step in our tour is the azuredeploy.parameters.json file. Please click on the corresponding entry in the Solution Explorer. Now, you should see the following screen:

Parameters are automatically adopted during the entire processing of the azuredeploy. json file, but can also be inserted manually (for example, to define default values).
The last step in our tour is the Deploy.AzureResourceGroup.ps1 file. Please click on the corresponding entry in the Solution Explorer. Now, you should see the following screen:

Again, all settings during the entire processing of the azuredeploy. json file are automatically taken over and can be manually inserted.