Bird
Raised Fist0
Azurecloud~10 mins

ARM template outputs in Azure - Step-by-Step Execution

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
Process Flow - ARM template outputs
Define Outputs Section
Reference Resource Properties
Assign Output Values
Deploy Template
Retrieve Outputs
Use Outputs in Scripts or UI
This flow shows how outputs are defined in an ARM template, assigned values from resources, deployed, and then retrieved for use.
Execution Sample
Azure
{
  "outputs": {
    "storageAccountName": {
      "type": "string",
      "value": "[variables('storageAccountName')]"
    }
  }
}
Defines an output named storageAccountName that returns the storage account name variable after deployment.
Process Table
StepActionEvaluationResult
1Define outputs section in templateOutputs section with storageAccountName keyOutputs section ready
2Assign value to outputValue set to variable 'storageAccountName'Output storageAccountName = 'mystorageacct123'
3Deploy ARM templateTemplate deploys resources and outputsResources created, outputs stored
4Retrieve outputs after deploymentQuery outputs from deployment resultstorageAccountName = 'mystorageacct123'
5Use output in script or UIReference output valueOutput value used successfully
6EndNo more outputs to retrieveExecution complete
💡 All outputs retrieved and deployment finished
Status Tracker
VariableStartAfter 1After 2Final
storageAccountNameundefinedmystorageacct123mystorageacct123mystorageacct123
Key Moments - 3 Insights
Why do outputs need a type like 'string' or 'object'?
Outputs require a type to tell Azure how to handle and display the value, as shown in step 2 of the execution_table where the output type is 'string'.
Can outputs reference resources created in the same template?
Yes, outputs often reference resource properties created during deployment, as in step 2 where the output value uses a variable linked to a resource.
When can you access the output values?
Outputs are accessible only after deployment completes successfully, as shown in step 4 where outputs are retrieved.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output value of 'storageAccountName' at step 2?
A"storageAccountName"
B"undefined"
C"mystorageacct123"
D"variables('storageAccountName')"
💡 Hint
Check the 'Result' column in row 2 of the execution_table.
At which step does the ARM template deployment complete and outputs become available?
AStep 4
BStep 3
CStep 5
DStep 2
💡 Hint
Look for when outputs are retrieved in the execution_table.
If the output type was missing, what would happen during deployment?
AOutput is ignored silently
BDeployment fails due to missing output type
COutput defaults to string type
DDeployment succeeds but output is unusable
💡 Hint
Refer to key_moments about output type importance.
Concept Snapshot
ARM template outputs let you return values after deployment.
Define outputs in the 'outputs' section with a name, type, and value.
Values often reference resource properties or variables.
Outputs are accessible only after deployment finishes.
Use outputs to pass info to scripts or other templates.
Full Transcript
ARM template outputs are defined in the outputs section of the template JSON. Each output has a name, a type like string or object, and a value that usually references a resource property or variable. When you deploy the template, Azure creates the resources and stores the output values. After deployment completes, you can retrieve these outputs to use in scripts, UI, or other templates. Outputs must have a type to be valid. This flow ensures you get important info like resource names or IDs after deployment.

Practice

(1/5)
1. What is the main purpose of outputs in an ARM template?
easy
A. To display important information after deployment
B. To define the resources to deploy
C. To specify deployment parameters
D. To set access permissions for resources

Solution

  1. Step 1: Understand the role of outputs in ARM templates

    Outputs are used to show key information after the deployment finishes, such as resource IDs or connection strings.
  2. Step 2: Differentiate outputs from other template sections

    Resources define what to deploy, parameters set inputs, and outputs show results after deployment.
  3. Final Answer:

    To display important information after deployment -> Option A
  4. Quick Check:

    Outputs = show info after deployment [OK]
Hint: Outputs always show info after deployment [OK]
Common Mistakes:
  • Confusing outputs with parameters
  • Thinking outputs define resources
  • Assuming outputs set permissions
2. Which of the following is the correct syntax to define an output named storageAccountName of type string in an ARM template?
easy
A. "outputs": { "storageAccountName": { "type": "string", "val": "[variables('storageName')]" } }
B. "outputs": { "storageAccountName": { "type": "string", "value": "[variables('storageName')]" } }
C. "outputs": { "storageAccountName": { "datatype": "string", "value": "[variables('storageName')]" } }
D. "outputs": { "storageAccountName": { "type": "string", "value": "variables('storageName')" } }

Solution

  1. Step 1: Check the required keys for output

    An output must have a "type" key specifying the data type and a "value" key with an expression or value.
  2. Step 2: Validate the syntax for referencing variables

    The value must be an expression in square brackets, e.g., "[variables('storageName')]".
  3. Final Answer:

    "outputs": { "storageAccountName": { "type": "string", "value": "[variables('storageName')]" } } -> Option B
  4. Quick Check:

    Output syntax = type + value with [expression] [OK]
Hint: Outputs need "type" and "value" keys with expressions in brackets [OK]
Common Mistakes:
  • Using 'datatype' instead of 'type'
  • Using 'val' instead of 'value'
  • Missing brackets around expressions
3. Given this output snippet in an ARM template:
"outputs": { "appEndpoint": { "type": "string", "value": "[concat('https://', reference(resourceId('Microsoft.Web/sites', variables('appName'))).defaultHostName)]" }}

What will appEndpoint output after deployment?
medium
A. The app name only
B. The resource ID of the web app
C. The full URL of the deployed web app
D. An error because of wrong syntax

Solution

  1. Step 1: Understand the expression used in the output value

    The expression uses concat to build a URL string starting with 'https://' and appends the defaultHostName property of the web app resource.
  2. Step 2: Determine what reference() returns

    reference() fetches runtime properties of the deployed resource, here the web app's hostname.
  3. Final Answer:

    The full URL of the deployed web app -> Option C
  4. Quick Check:

    Output builds URL using reference() = full URL [OK]
Hint: reference() gets deployed resource info, concat builds URL [OK]
Common Mistakes:
  • Thinking output returns resource ID instead of hostname
  • Confusing variable name with output value
  • Assuming syntax error due to complex expression
4. You have this output defined:
"outputs": { "storageKey": { "type": "string", "value": "listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('storageName')), '2021-04-01').keys[0].value" }}

After deployment, you get an error. What is the likely cause?
medium
A. Missing square brackets around the expression value
B. Incorrect API version in listKeys function
C. Output type should be 'securestring' instead of 'string'
D. Variables section missing the storageName variable

Solution

  1. Step 1: Check the syntax for output value expressions

    Output values must be enclosed in square brackets to indicate an expression, e.g., "[expression]".
  2. Step 2: Identify the missing brackets in the given output

    The value is missing the surrounding brackets, so ARM treats it as a literal string causing an error.
  3. Final Answer:

    Missing square brackets around the expression value -> Option A
  4. Quick Check:

    Output expressions need [ ] brackets [OK]
Hint: Always wrap output expressions in [ ] brackets [OK]
Common Mistakes:
  • Forgetting brackets around expressions
  • Assuming API version is wrong without checking
  • Confusing output type with expression syntax
5. You want to output a list of VM names created by a loop in your ARM template. Which output definition correctly returns an array of VM names?
hard
A. "outputs": { "vmNames": { "type": "array", "value": "[array(variables('vmNames'))]" } }
B. "outputs": { "vmNames": { "type": "object", "value": "variables('vmNames')" } }
C. "outputs": { "vmNames": { "type": "string", "value": "[variables('vmNames')]" } }
D. "outputs": { "vmNames": { "type": "array", "value": "[variables('vmNames')]" } }

Solution

  1. Step 1: Identify the correct output type for a list of names

    A list of VM names is an array, so the output type should be "array".
  2. Step 2: Check the syntax for output value expressions

    The value must be an expression enclosed in brackets, e.g., "[variables('vmNames')]". Wrapping with array() is unnecessary if vmNames is already an array.
  3. Final Answer:

    "outputs": { "vmNames": { "type": "array", "value": "[variables('vmNames')]" } } -> Option D
  4. Quick Check:

    Output array = type array + value in [ ] [OK]
Hint: Use type 'array' and wrap value in [ ] brackets [OK]
Common Mistakes:
  • Using type 'string' for arrays
  • Omitting brackets around expressions
  • Adding unnecessary array() function