Bird
Raised Fist0
Azurecloud~30 mins

ARM template parameters and variables in Azure - Mini Project: Build & Apply

Choose your learning style10 modes available
ARM template parameters and variables
📖 Scenario: You are setting up an Azure Resource Manager (ARM) template to deploy a simple storage account. You want to make the template flexible by using parameters and variables.
🎯 Goal: Create an ARM template that uses parameters to accept the storage account name and location, and variables to define the storage account kind and SKU. This template will help you deploy storage accounts with different names and locations easily.
📋 What You'll Learn
Use a parameter called storageAccountName with type string.
Use a parameter called location with type string.
Create a variable called storageAccountKind with value StorageV2.
Create a variable called storageAccountSku with value Standard_LRS.
Use the parameters and variables in the storage account resource definition.
💡 Why This Matters
🌍 Real World
ARM templates are used to automate Azure resource deployment with reusable and configurable templates.
💼 Career
Understanding parameters and variables in ARM templates is essential for cloud engineers and DevOps professionals managing Azure infrastructure.
Progress0 / 4 steps
1
Create ARM template parameters
Create the parameters section in the ARM template JSON with two parameters: storageAccountName of type string and location of type string.
Azure
Hint

Parameters let you pass values when deploying the template. Use the exact names storageAccountName and location with type string.

2
Add variables for storage account kind and SKU
Add a variables section with two variables: storageAccountKind set to StorageV2 and storageAccountSku set to Standard_LRS.
Azure
Hint

Variables hold values you want to reuse inside the template. Use the exact variable names and values.

3
Add storage account resource using parameters and variables
Add a resource of type Microsoft.Storage/storageAccounts with name from parameters('storageAccountName'), location from parameters('location'), kind from variables('storageAccountKind'), and sku name from variables('storageAccountSku'). Use API version 2021-04-01.
Azure
Hint

Use the parameters() and variables() functions to reference values inside the resource definition.

4
Add output for storage account resource ID
Add an outputs section with an output named storageAccountId that returns the resource ID of the storage account using resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')).
Azure
Hint

Outputs let you get information from the deployed resources. Use the resourceId function with the exact syntax shown.

Practice

(1/5)
1.

What is the main purpose of parameters in an ARM template?

easy
A. To define the resources to deploy
B. To allow input values when deploying the template
C. To store fixed values inside the template
D. To specify deployment location only

Solution

  1. Step 1: Understand parameters role

    Parameters let users provide input values at deployment time, making templates flexible.
  2. Step 2: Differentiate from variables

    Variables store fixed or computed values inside the template, not input values.
  3. Final Answer:

    To allow input values when deploying the template -> Option B
  4. Quick Check:

    Parameters = input values [OK]
Hint: Parameters accept inputs during deployment, variables do not [OK]
Common Mistakes:
  • Confusing parameters with variables
  • Thinking parameters define resources
  • Assuming parameters are fixed values
2.

Which of the following is the correct syntax to declare a variable named storageAccountName in an ARM template?

{
  "variables": {
    "storageAccountName": "myStorage"
  }
}
easy
A. "resources": { "storageAccountName": "myStorage" }
B. "parameters": { "storageAccountName": "myStorage" }
C. "variables": { "storageAccountName": "myStorage" }
D. "outputs": { "storageAccountName": "myStorage" }

Solution

  1. Step 1: Identify variable declaration section

    Variables are declared inside the "variables" section as key-value pairs.
  2. Step 2: Match syntax with example

    The example shows "variables": { "storageAccountName": "myStorage" }, which matches "variables": { "storageAccountName": "myStorage" }.
  3. Final Answer:

    "variables": { "storageAccountName": "myStorage" } -> Option C
  4. Quick Check:

    Variables declared under "variables" [OK]
Hint: Variables go inside "variables" block, not parameters or resources [OK]
Common Mistakes:
  • Putting variables inside parameters
  • Confusing variables with outputs
  • Using wrong JSON section names
3.

Given this ARM template snippet, what will be the value of variables('fullName')?

{
  "parameters": {
    "firstName": { "type": "string", "defaultValue": "John" },
    "lastName": { "type": "string", "defaultValue": "Doe" }
  },
  "variables": {
    "fullName": "[concat(parameters('firstName'), ' ', parameters('lastName'))]"
  }
}
medium
A. parameters('firstName') parameters('lastName')
B. JohnDoe
C. [concat(parameters('firstName'), ' ', parameters('lastName'))]
D. John Doe

Solution

  1. Step 1: Understand concat function in variables

    The variable "fullName" uses concat to join firstName, a space, and lastName.
  2. Step 2: Substitute default parameter values

    firstName = "John", lastName = "Doe", so concat("John", " ", "Doe") = "John Doe".
  3. Final Answer:

    John Doe -> Option D
  4. Quick Check:

    concat with space joins names [OK]
Hint: concat joins strings; default parameters fill in values [OK]
Common Mistakes:
  • Taking concat as literal string
  • Ignoring space between names
  • Confusing parameters with variables
4.

Identify the error in this ARM template snippet:

{
  "parameters": {
    "location": { "type": "string" }
  },
  "variables": {
    "region": "parameters('location')"
  }
}
medium
A. Missing square brackets around the parameter reference in variable
B. Variable names cannot be 'region'
C. Parameter type must be 'securestring' to use in variables
D. Variables cannot reference parameters

Solution

  1. Step 1: Check variable referencing syntax

    Variables referencing parameters must use expression syntax with square brackets: "[parameters('location')]".
  2. Step 2: Identify missing brackets

    The variable "region" is assigned "parameters('location')" as a string, not an expression.
  3. Final Answer:

    Missing square brackets around the parameter reference in variable -> Option A
  4. Quick Check:

    Parameter references need [ ] in variables [OK]
Hint: Use [parameters('name')] inside variables, not plain strings [OK]
Common Mistakes:
  • Omitting square brackets for expressions
  • Thinking variables can't use parameters
  • Wrong parameter types for variables
5.

You want to create an ARM template that deploys a storage account with a name based on a parameter prefix and a variable uniqueString. Which is the best way to combine them in the template?

{
  "parameters": {
    "prefix": { "type": "string" }
  },
  "variables": {
    "uniqueString": "[uniqueString(resourceGroup().id)]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "???",
      "apiVersion": "2022-09-01",
      "location": "[resourceGroup().location]"
    }
  ]
}

Choose the correct expression to use for the storage account name property.

hard
A. "[concat(parameters('prefix'), variables('uniqueString'))]"
B. "parameters('prefix') + variables('uniqueString')"
C. "[parameters('prefix') variables('uniqueString')]"
D. "concat(parameters.prefix, variables.uniqueString)"

Solution

  1. Step 1: Understand ARM template expression syntax

    Expressions must be inside square brackets and use functions like concat() to join strings.
  2. Step 2: Check correct usage of parameters and variables

    Use parameters('name') and variables('name') inside concat() within brackets.
  3. Step 3: Evaluate options

    "[concat(parameters('prefix'), variables('uniqueString'))]" uses correct syntax: "[concat(parameters('prefix'), variables('uniqueString'))]".
  4. Final Answer:

    "[concat(parameters('prefix'), variables('uniqueString'))]" -> Option A
  5. Quick Check:

    Use [concat(parameters('x'), variables('y'))] for combined names [OK]
Hint: Use [concat(parameters('x'), variables('y'))] for combined strings [OK]
Common Mistakes:
  • Using + instead of concat inside brackets
  • Omitting square brackets for expressions
  • Wrong syntax for parameters or variables
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard