Modifying an ARM template

In this demonstration, we are going to create an ARM template of a storage account in the Azure portal. We are going to modify this template so that it will generate a storage account name automatically. We will then deploy this template again and use it to create a new storage account from the Azure portal. Therefore, you have to take the following steps:

  1. Navigate to the Azure portal by opening https://portal.azure.com.
  2. Select Create a resource, then Storage and then select Storage account. Create a new storage account.
  3. Add the following values:
    • Subscription: Pick a subscription.
    • Resource group: Create a new one and call it PacktARMResourceGroup.
    • Storage account name: Type packtarm.
    • Location: Select (US) East US.
    • Performance: Select Standard.
    • Account kind: Select StorageV2 (general purpose v2).
    • Replication: Select Read-access geo-redundant storage (RA-GRS).
    • Access tier: Select Hot.
  1. Click Review + create. Do not select Create.
  2. But, in the next step, select Download a template for automation:

Download template for automation
  1. The editor will be opened and the generated template will be displayed. The main pane shows the template. It has six top-level elements: schema, contentVersionparametersvariablesresources, and output. There are also six parameters. storageAccountName is highlighted in the following screenshot. In the template, one Azure resource is defined. The type is Microsoft.Storage/storageAccounts. Select Download from the top menu:

Main ARM template
  1. Open the downloaded ZIP file and then save template.json to your computer. In the next section, you will use a template deployment tool to edit the template.
  2. Select Parameters in the top menu and look at the values. We will need this later during the deployment:

ARM template parameters
  1. The Azure portal can be used for the basic editing of ARM templates. More complex ARM templates can be edited using Visual Studio Code, for instance. We are going to use the Azure portal for this demonstration. Therefore, select + Create a resource; then, in the search box, type Template Deployment (deploy using custom templates). Then select Create.
  2. In the next blade, you have different options for loading templates. For this demonstration, select Build your own template in the editor:

Template options
  1. Select Load file, and then follow the instructions to load template.json, which we downloaded in the last section. Make the following changes:
    1. Remove the storageAccountName parameter.
    2. Add a new variable:
"storageAccountName": "[concat(uniqueString(subscription().subscriptionId), 'storage')]",
    1. Replace "name": "[parameters('storageAccountName')]", with "name": "[variables('storageAccountName')]":

Make changes to the highlighted sections
    1. The code of the template will look as follows:

The schema and parameters sections are as follows:

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"accountType": {
"type": "string"
},
"kind": {
"type": "string"
},
"accessTier": {
"type": "string"
},
"supportsHttpsTrafficOnly": {
"type": "bool"
}
},

The variable and resources section is as follows:

    "variables": {
"storageAccountName": "[concat(uniqueString(subscription().subscriptionId), 'storage')]"
},
"resources": [
{
"name": "[variables('storageAccountName')]",
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2018-07-01",
"location": "[parameters('location')]",
"properties": {
"accessTier": "[parameters('accessTier')]",
"supportsHttpsTrafficOnly": "[parameters('supportsHttpsTrafficOnly')]"
},
"dependsOn": [],
"sku": {
"name": "[parameters('accountType')]"
},
"kind": "[parameters('kind')]"
}
],
"outputs": {}
}

    1. Then select Save.
  1. In the next screen, fill in the values for creating the storage account. You will see that the parameter for filling in the storage account name is removed. This will be generated automatically. Fill in the following values:
    • Resource group: Select the resource group name you created in the previous section.
    • Location: Select East US.
    • Account typeSelect Standard_LRS.
    • KindSelect StorageV2.
    • Access Tier: Select Hot.
    • Https Traffic Only Enabled: Select true.
    • I agree to the terms and conditions stated above: Select this checkbox.
  1. Select Purchase.
  2. The ARM template will now be deployed. After deployment, go to the Overview blade of the resource group. You will see that the storage account name is automatically generated for you:

Storage account name
For more information about the syntax and structure of ARM templates, you can refer to the following website: https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates.

We have now modified an ARM template in the Azure portal and created a new storage account using the modified ARM templates. In the next demonstration, we are going to save a deployment as an ARM template.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset