azure-az104-flashcards

Azure Resource Manager Templates

Powershell

$ pwsh
$ PS> Connect-AzAccount
$ PS> New-AzResourceGroupDeployment -ResourceGroupName arm-grp -TemplateFile scripts/arm/arm-variable.json

Template format

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "",
  "apiProfile": "",
  "parameters": {  },
  "variables": {  },
  "functions": [  ],
  "resources": [  ],
  "outputs": {  }
}

Deployment via Azure Portal

Scripts

Other scripts can be found here.

Elements

Resource id

Extract the id of that specific resource.

"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'enrico-vn', 'subnet1')]" 

Resource Group location

"location": "[resourceGroup().location]",

Variables

 "variables": {
        "resourceLocation" : "North Europe"
    },
    "resources": [
        {           
            "name": "storage",
            "type": "Microsoft.Storage/storageAccounts",
            "location":"[variables('resourceLocation')]",

        }

Parameters

If you do not pass at runtime the value(s), then default value is taken.

   "parameters": {
            "storage-sku": {
                "type": "string",
                "defaultValue":"Standard_LRS",
                "allowedValues": [
                    "Standard_LRS","Standard_GRS","Standard_RAGRS"
                ]
            }
    },
    "resources": [
        {           
          ...

            "sku" :{
                "name": "[parameters('storage-sku')]"
            },
        }
            ]

Complete file is here

You can either using Azure Portal o pass the parameter with another file:

$ PS>  New-AzResourceGroupDeployment -ResourceGroupName az-104 -TemplateFile ./scripts/arm/arm-storage-with-parameters.json -TemplateParameterFile ./scripts/arm/parameter.json

securestring

"parameters": {
        "vmpassowrd":{
            "type": "securestring",
            "metadata": {
                "description": "Please type the password"
            }
        }
    },

copyIndex

"resources": [
        {
            "name": "[concat('enricosa',copyIndex())]",
            ...
            "copy": {
                "name":"storagecopy",
                "count": 3
            }
        }
    ]

copyIndex

dependsOn

"dependsOn": [
    "[resourceId('Microsoft.Network/networkSecurityGroups', variables('MetworkSG'))]"
],

Parameters file

$ New-AzResourceGroupDeployment -ResourceGroupName az-104 -TemplateFile ./scripts/arm/arm-storage-account-with-parameters.json  -TemplateParameterFile  ./scripts/arm/params-sa.json

Deply vm - section

         "imageReference": {
                        "publisher": "MicrosoftWindowsServer",
                        "offer": "WindowsServer",
                        "sku": "2019-datacenter-gensecond",
                        "version": "latest"
                    },

offer/sku: :bangbang:

Various

How to use ARM deployment templates with Azure CLI

:bangbang:

$ az deployment group create --resource-group <resource-group-name> --template-file <path-to-template>

Understand the structure and syntax of ARM template

docs