Bird
Raised Fist0
Azurecloud~5 mins

Template deployment methods in Azure - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Deploying resources in Azure can be repetitive and error-prone if done manually. Template deployment methods let you define your infrastructure as code, so you can create and manage resources consistently and quickly.
When you want to create multiple Azure resources together in a repeatable way.
When you need to share your infrastructure setup with your team or automate deployments.
When you want to keep track of your infrastructure changes in version control.
When you want to deploy the same environment multiple times, like for testing or production.
When you want to avoid manual errors by using a predefined configuration.
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 to create"
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2021-04-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 Azure Resource Manager (ARM) template.

parameters: Defines input values like the storage account name.

resources: Describes the Azure resources to create, here a storage account in East US.

outputs: Returns useful info after deployment, like the resource ID.

Commands
Create a resource group named 'example-resource-group' in the East US region to hold your resources.
Terminal
az group create --name example-resource-group --location eastus
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resource-group", "location": "eastus", "managedBy": null, "name": "example-resource-group", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Specifies the resource group name
--location - Specifies the Azure region
Deploy the ARM template to the resource group, creating the storage account with the given name.
Terminal
az deployment group create --resource-group example-resource-group --template-file azuredeploy.json --parameters storageAccountName=examplestorageacct
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resource-group/providers/Microsoft.Resources/deployments/deployment1", "name": "deployment1", "properties": { "provisioningState": "Succeeded", "outputs": { "storageAccountId": { "type": "String", "value": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resource-group/providers/Microsoft.Storage/storageAccounts/examplestorageacct" } } }, "type": "Microsoft.Resources/deployments" }
--resource-group - Specifies the target resource group
--template-file - Specifies the ARM template file to deploy
--parameters - Passes parameters to the template
Verify that the storage account was created successfully by showing its details.
Terminal
az storage account show --name examplestorageacct --resource-group example-resource-group
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example-resource-group/providers/Microsoft.Storage/storageAccounts/examplestorageacct", "location": "eastus", "name": "examplestorageacct", "primaryEndpoints": { "blob": "https://examplestorageacct.blob.core.windows.net/", "file": "https://examplestorageacct.file.core.windows.net/", "queue": "https://examplestorageacct.queue.core.windows.net/", "table": "https://examplestorageacct.table.core.windows.net/" }, "sku": { "name": "Standard_LRS", "tier": "Standard" }, "tags": {}, "type": "Microsoft.Storage/storageAccounts" }
--name - Specifies the storage account name
--resource-group - Specifies the resource group name
Key Concept

If you remember nothing else from this pattern, remember: ARM templates let you define and deploy Azure resources consistently using code.

Common Mistakes
Not creating the resource group before deploying the template.
The deployment fails because the target resource group does not exist.
Always create the resource group first using 'az group create' before deploying.
Using invalid or already taken storage account names.
Storage account names must be globally unique and follow naming rules, otherwise deployment fails.
Choose a unique, lowercase name between 3 and 24 characters with only numbers and letters.
Forgetting to pass required parameters when deploying the template.
The deployment will fail if required parameters are missing or incorrect.
Use the '--parameters' flag to provide all required inputs.
Summary
Create a resource group to hold your Azure resources.
Deploy an ARM template file with parameters to create resources automatically.
Verify the deployment by checking the created resources.

Practice

(1/5)
1. What is the main purpose of using an Azure Resource Manager (ARM) template for deployment?
easy
A. To manually create resources one by one in the Azure portal
B. To write code for a web application
C. To automate the creation and configuration of cloud resources
D. To monitor resource usage and billing

Solution

  1. Step 1: Understand ARM template purpose

    ARM templates are JSON files that define infrastructure and configuration in a repeatable way.
  2. Step 2: Compare options

    Only To automate the creation and configuration of cloud resources describes automation of resource creation, which is the core use of ARM templates.
  3. Final Answer:

    To automate the creation and configuration of cloud resources -> Option C
  4. Quick Check:

    ARM templates automate deployments [OK]
Hint: Templates automate resource setup, not manual or monitoring tasks [OK]
Common Mistakes:
  • Confusing templates with manual portal actions
  • Thinking templates are for app coding
  • Mixing deployment with monitoring
2. Which Azure CLI command correctly deploys a resource group using an ARM template file named template.json with parameters in params.json?
easy
A. az resource deploy --group MyGroup --template template.json --params params.json
B. az group create --template template.json --params params.json
C. az deployment create --resource MyGroup --template template.json --parameters params.json
D. az deployment group create --resource-group MyGroup --template-file template.json --parameters params.json

Solution

  1. Step 1: Identify correct Azure CLI syntax for group deployment

    The correct command is az deployment group create with flags for resource group, template file, and parameters.
  2. Step 2: Check each option

    Only az deployment group create --resource-group MyGroup --template-file template.json --parameters params.json uses the correct command and flags as per Azure CLI documentation.
  3. Final Answer:

    az deployment group create --resource-group MyGroup --template-file template.json --parameters params.json -> Option D
  4. Quick Check:

    Use az deployment group create for group deployments [OK]
Hint: Use 'az deployment group create' with --resource-group flag [OK]
Common Mistakes:
  • Using 'az group create' which creates resource groups, not deploys templates
  • Wrong command verbs like 'deploy' or 'resource deploy'
  • Incorrect flag names like --template instead of --template-file
3. Given this Azure CLI command:
az deployment sub create --location eastus --template-file main.json --parameters storageAccountName=mystorage
What is the scope of this deployment?
medium
A. Deploys resources at the management group level
B. Deploys resources at the subscription level
C. Deploys resources inside a resource group
D. Deploys resources only in the eastus resource group

Solution

  1. Step 1: Analyze the command scope

    The command uses az deployment sub create, which means deployment at the subscription scope.
  2. Step 2: Understand location and parameters

    The --location flag is required for subscription deployments; parameters define resource details.
  3. Final Answer:

    Deploys resources at the subscription level -> Option B
  4. Quick Check:

    az deployment sub create = subscription scope [OK]
Hint: 'sub create' means subscription-level deployment [OK]
Common Mistakes:
  • Confusing subscription with resource group scope
  • Assuming location defines resource group
  • Mixing management group with subscription
4. You run this command to deploy a template:
az deployment group create --resource-group MyGroup --template-file template.json
But you get an error saying parameters are missing. What is the likely cause?
medium
A. The template requires parameters but none were provided
B. The resource group MyGroup does not exist
C. The template file template.json is not valid JSON
D. The Azure CLI is not installed

Solution

  1. Step 1: Understand error message

    The error about missing parameters means the template expects input values not given in the command.
  2. Step 2: Check command and options

    The command does not include --parameters, so required parameters are missing.
  3. Final Answer:

    The template requires parameters but none were provided -> Option A
  4. Quick Check:

    Missing parameters cause deployment errors [OK]
Hint: Always provide required parameters with --parameters flag [OK]
Common Mistakes:
  • Assuming resource group missing causes parameter error
  • Ignoring template validation errors
  • Not verifying Azure CLI installation
5. You want to deploy a template at the management group level to apply policies across multiple subscriptions. Which Azure CLI command should you use?
hard
A. az deployment mg create --management-group-id MyMgmtGroup --location eastus --template-file policy.json
B. az deployment group create --resource-group MyGroup --template-file policy.json
C. az deployment sub create --subscription MySubscription --template-file policy.json
D. az deployment create --template-file policy.json

Solution

  1. Step 1: Identify deployment scope for management groups

    Management group deployments use az deployment mg create with the management group ID.
  2. Step 2: Compare options

    az deployment mg create --management-group-id MyMgmtGroup --location eastus --template-file policy.json correctly uses the management group deployment command and specifies the management group ID.
  3. Final Answer:

    az deployment mg create --management-group-id MyMgmtGroup --location eastus --template-file policy.json -> Option A
  4. Quick Check:

    Use az deployment mg create for management group scope [OK]
Hint: Use 'az deployment mg create' for management group deployments [OK]
Common Mistakes:
  • Using group or subscription commands for management group scope
  • Omitting management group ID
  • Using incomplete commands without scope