0
0
Azurecloud~5 mins

Azure Resource Manager (ARM) concept - Commands & Configuration

Choose your learning style9 modes available
Introduction
Managing cloud resources can be confusing when done one by one. Azure Resource Manager helps organize and control these resources together as a group, making deployment and management easier and consistent.
When you want to deploy multiple related cloud resources like virtual machines, storage, and networks together.
When you need to update or delete a group of resources safely without affecting others.
When you want to track and control access to your cloud resources in a clear way.
When you want to automate deployments using a reusable template.
When you want to see all resources related to a project in one place.
Config File - azuredeploy.json
azuredeploy.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountName": {
      "type": "string",
      "defaultValue": "examplestorage123",
      "metadata": {
        "description": "Name of the storage account"
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2022-09-01",
      "name": "[parameters('storageAccountName')]",
      "location": "eastus",
      "sku": {
        "name": "Standard_LRS"
      },
      "kind": "StorageV2",
      "properties": {}
    }
  ],
  "outputs": {
    "storageAccountId": {
      "type": "string",
      "value": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
    }
  }
}

This JSON file is an ARM template that defines a storage account resource.

parameters: Allows setting the storage account name when deploying.

resources: Defines the storage account with location, SKU, and kind.

outputs: Returns the resource ID of the created storage account after deployment.

Commands
This command creates a resource group named 'exampleResourceGroup' in the East US region. Resource groups hold related resources together.
Terminal
az group create --name exampleResourceGroup --location eastus
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/exampleResourceGroup", "location": "eastus", "managedBy": null, "name": "exampleResourceGroup", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Sets the name of the resource group
--location - Specifies the Azure region for the resource group
This command deploys the ARM template file 'azuredeploy.json' to the resource group 'exampleResourceGroup', creating the storage account defined in the template.
Terminal
az deployment group create --resource-group exampleResourceGroup --template-file azuredeploy.json
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/exampleResourceGroup/providers/Microsoft.Resources/deployments/deployment202406", "name": "deployment202406", "properties": { "provisioningState": "Succeeded", "outputs": { "storageAccountId": { "type": "String", "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/exampleResourceGroup/providers/Microsoft.Storage/storageAccounts/examplestorage123" } } }, "resourceGroup": "exampleResourceGroup", "timestamp": "2024-06-01T12:00:00Z", "type": "Microsoft.Resources/deployments" }
--resource-group - Specifies the target resource group for deployment
--template-file - Points to the ARM template file to deploy
This command retrieves details about the storage account named 'examplestorage123' in the resource group to verify it was created successfully.
Terminal
az storage account show --name examplestorage123 --resource-group exampleResourceGroup
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/exampleResourceGroup/providers/Microsoft.Storage/storageAccounts/examplestorage123", "location": "eastus", "name": "examplestorage123", "primaryEndpoints": { "blob": "https://examplestorage123.blob.core.windows.net/", "file": "https://examplestorage123.file.core.windows.net/", "queue": "https://examplestorage123.queue.core.windows.net/", "table": "https://examplestorage123.table.core.windows.net/" }, "sku": { "name": "Standard_LRS" }, "tags": {}, "type": "Microsoft.Storage/storageAccounts" }
--name - Specifies the storage account name to show
--resource-group - Specifies the resource group containing the storage account
Key Concept

If you remember nothing else from this pattern, remember: ARM templates let you define and manage related Azure resources together as one unit for easy deployment and control.

Common Mistakes
Trying to deploy an ARM template without creating the resource group first.
The deployment fails because the target resource group does not exist to hold the resources.
Always create the resource group with 'az group create' before deploying the ARM template.
Using an invalid or missing parameter value in the ARM template during deployment.
Deployment fails or creates resources with wrong names or settings.
Check and provide correct parameter values either in the template or via command line parameters.
Not verifying the deployment result and assuming resources were created.
You might think resources exist when deployment failed or was incomplete.
Use commands like 'az storage account show' or 'az deployment group show' to confirm successful deployment.
Summary
Create a resource group to hold your Azure resources.
Deploy an ARM template to create and configure resources in that group.
Verify the resources were created successfully using Azure CLI commands.