Azure Classroom Series – 02/Jun/2020

ARM Templates

  • Why ARM Templates
    • Repeatable and consistent Infrastructure creation
    • Infrastructure as Code (IAC)
  • Approach for effective Template writing?
    • Template creator needs to know manual steps
      • What has to be created will be clear
      • Order of creation
    • Template creator should know about
      • parameters
      • variables
      • resources
      • outputs
      • conditions
      • functions

Scenario: Create a network with 4 subnets

  • Portal: Steps are
    • Create/pick a resource group
    • Create a vnet with address range of 192.168.0.0/16
    • Create a subnet with
      • Name: subnet1 address range => 192.168.0.0/24
      • Name: subnet2 address range => 192.168.1.0/24
      • Name: subnet3 address range => 192.168.2.0/24
      • Name: subnet4 address range => 192.168.3.0/24
  • Writing Template
    • Anything which we create is a resource (most of the times)
    • Lets start from basic template and add the resources
    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "0.0.0.1",
        "resources": [
            {
                "name": "armvnet",
                "type": "Microsoft.Network/virtualNetworks",
                "apiVersion": "2020-04-01",
                "location": "eastus",
                "properties": {
                    "addressSpace": {
                        "addressPrefixes": [
                            "192.168.0.0/16"
                        ]
                    },
                    "subnets": [
                        {
                            "name": "subnet1",
                            "properties": {
                                "addressPrefix": "192.168.0.0/24"
                            }
                        },
                        {
                            "name": "subnet2",
                            "properties": {
                                "addressPrefix": "192.168.1.0/24"
                            }
                        },
                        {
                            "name": "subnet3",
                            "properties": {
                                "addressPrefix": "192.168.2.0/24"
                            }
                        },
                        {
                            "name": "subnet4",
                            "properties": {
                                "addressPrefix": "192.168.3.0/24"
                            }
                        }
                    ]
                }
            }
        ]
    
    }
    
    • Now create a deployment for the template Preview Preview Preview Preview Preview
    • Now Go the Virtual network and verify the resources created
    • Navigate to the Resource group => Deployments Preview
    • Now try to add a storage account to the deployment Preview Preview
    • So the total template will be as shown below and create the deployment for that to see storage account
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "0.0.0.1",
    "resources": [
        {
            "name": "armvnet",
            "type": "Microsoft.Network/virtualNetworks",
            "apiVersion": "2020-04-01",
            "location": "eastus",
            "properties": {
                "addressSpace": {
                    "addressPrefixes": [
                        "192.168.0.0/16"
                    ]
                },
                "subnets": [
                    {
                        "name": "subnet1",
                        "properties": {
                            "addressPrefix": "192.168.0.0/24"
                        }
                    },
                    {
                        "name": "subnet2",
                        "properties": {
                            "addressPrefix": "192.168.1.0/24"
                        }
                    },
                    {
                        "name": "subnet3",
                        "properties": {
                            "addressPrefix": "192.168.2.0/24"
                        }
                    },
                    {
                        "name": "subnet4",
                        "properties": {
                            "addressPrefix": "192.168.3.0/24"
                        }
                    },
                    
                    {
                        "name": "subnet5",
                        "properties": {
                            "addressPrefix": "192.168.4.0/24"
                        }
                    },
                    {
                        "name": "subnet6",
                        "properties": {
                            "addressPrefix": "192.168.5.0/24"
                        }
                    }

                ]
            }
        },
        {
            "name": "qtstoragedemoarm",
            "type": "Microsoft.Storage/storageAccounts",
            "apiVersion": "2019-06-01",
            "tags": {
                "displayName": "qtstoragedemoarm"
            },
            "location": "eastus",
            "kind": "StorageV2",
            "sku": {
                "name": "Standard_RAGRS",
                "tier": "Standard"
            },
            "properties": {
                "accessTier": "Hot"
            }
        }
    ]

}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin