0
0
Azurecloud~5 mins

ARM template structure in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you want to create or update resources in Azure, you need a clear plan. ARM templates help you describe what resources you want and how they connect, so Azure can build them automatically.
When you want to create a virtual machine and its network settings together in one step.
When you need to set up a storage account and a database at the same time.
When you want to repeat the same setup in different Azure regions without mistakes.
When you want to share your infrastructure setup with teammates or save it for later.
When you want to update or delete resources safely by changing the template.
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",
      "metadata": {
        "description": "Name of the storage account"
      }
    }
  },
  "variables": {},
  "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'))]"
    }
  }
}

$schema: Defines the template schema version for validation.

contentVersion: Version of your template for tracking changes.

parameters: Inputs you provide when deploying, like the storage account name.

variables: Values you can reuse inside the template (empty here).

resources: The Azure resources to create, here a storage account with its settings.

outputs: Values returned after deployment, like the resource ID of the storage account.

Commands
This command deploys the ARM template to the resource group named 'example-rg', creating the storage account with the name 'examplestorage123'.
Terminal
az deployment group create --resource-group example-rg --template-file azuredeploy.json --parameters storageAccountName=examplestorage123
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Resources/deployments/deploymentName", "name": "deploymentName", "properties": { "provisioningState": "Succeeded", "outputs": { "storageAccountId": { "type": "String", "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorage123" } } }, "type": "Microsoft.Resources/deployments" }
--resource-group - Specifies the Azure resource group where resources will be deployed.
--template-file - Points to the ARM template file to use for deployment.
--parameters - Provides values for the parameters defined in the template.
This command checks the details of the storage account created to confirm it exists and see its properties.
Terminal
az storage account show --name examplestorage123 --resource-group example-rg
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-rg/providers/Microsoft.Storage/storageAccounts/examplestorage123", "location": "eastus", "name": "examplestorage123", "sku": { "name": "Standard_LRS", "tier": "Standard" }, "kind": "StorageV2", "properties": { "provisioningState": "Succeeded" }, "resourceGroup": "example-rg", "type": "Microsoft.Storage/storageAccounts" }
--name - Specifies the name of the storage account to show.
--resource-group - Specifies the resource group where the storage account exists.
Key Concept

If you remember nothing else from this pattern, remember: ARM templates describe your Azure resources in a clear, repeatable way so Azure can build them automatically.

Common Mistakes
Using a storage account name that is too short or contains invalid characters.
Azure requires storage account names to be between 3 and 24 characters and use only lowercase letters and numbers.
Choose a name that meets Azure's naming rules, like 'examplestorage123'.
Forgetting to specify the resource group in the deployment command.
Without the resource group, Azure doesn't know where to create the resources and the command fails.
Always include the --resource-group flag with the correct group name.
Editing the template file with syntax errors like missing commas or braces.
JSON syntax errors prevent the template from deploying and cause confusing error messages.
Use a JSON validator or editor that highlights syntax errors before deploying.
Summary
ARM templates use JSON to describe Azure resources and their settings.
You deploy templates with the Azure CLI using 'az deployment group create' and provide parameters.
After deployment, you verify resources exist with commands like 'az storage account show'.