ARM template outputs in Azure - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When deploying resources with ARM templates, outputs help us get information after deployment.
We want to know how the time to get outputs changes as we add more outputs.
Analyze the time complexity of retrieving outputs from an ARM template deployment.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {
"output1": { "type": "string", "value": "value1" },
"output2": { "type": "int", "value": 123 },
"outputN": { "type": "string", "value": "valueN" }
}
}
This template defines multiple outputs that return values after deployment.
Look at what happens when outputs are processed:
- Primary operation: Reading each output value from the deployment result.
- How many times: Once per output defined in the template.
Each output adds one more value to retrieve after deployment.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 output retrieval operations |
| 100 | 100 output retrieval operations |
| 1000 | 1000 output retrieval operations |
Pattern observation: The number of retrievals grows directly with the number of outputs.
Time Complexity: O(n)
This means the time to get outputs grows linearly as you add more outputs.
[X] Wrong: "Getting outputs happens instantly no matter how many there are."
[OK] Correct: Each output requires a separate retrieval step, so more outputs take more time.
Understanding how output retrieval scales helps you design templates that stay efficient as they grow.
"What if outputs included nested objects instead of simple values? How would the time complexity change?"
Practice
outputs in an ARM template?Solution
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.Step 2: Differentiate outputs from other template sections
Resources define what to deploy, parameters set inputs, and outputs show results after deployment.Final Answer:
To display important information after deployment -> Option AQuick Check:
Outputs = show info after deployment [OK]
- Confusing outputs with parameters
- Thinking outputs define resources
- Assuming outputs set permissions
storageAccountName of type string in an ARM template?Solution
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.Step 2: Validate the syntax for referencing variables
The value must be an expression in square brackets, e.g., "[variables('storageName')]".Final Answer:
"outputs": { "storageAccountName": { "type": "string", "value": "[variables('storageName')]" } } -> Option BQuick Check:
Output syntax = type + value with [expression] [OK]
- Using 'datatype' instead of 'type'
- Using 'val' instead of 'value'
- Missing brackets around expressions
"outputs": { "appEndpoint": { "type": "string", "value": "[concat('https://', reference(resourceId('Microsoft.Web/sites', variables('appName'))).defaultHostName)]" }}What will
appEndpoint output after deployment?Solution
Step 1: Understand the expression used in the output value
The expression usesconcatto build a URL string starting with 'https://' and appends thedefaultHostNameproperty of the web app resource.Step 2: Determine what
reference()returnsreference()fetches runtime properties of the deployed resource, here the web app's hostname.Final Answer:
The full URL of the deployed web app -> Option CQuick Check:
Output builds URL using reference() = full URL [OK]
- Thinking output returns resource ID instead of hostname
- Confusing variable name with output value
- Assuming syntax error due to complex expression
"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?
Solution
Step 1: Check the syntax for output value expressions
Output values must be enclosed in square brackets to indicate an expression, e.g., "[expression]".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.Final Answer:
Missing square brackets around the expression value -> Option AQuick Check:
Output expressions need [ ] brackets [OK]
- Forgetting brackets around expressions
- Assuming API version is wrong without checking
- Confusing output type with expression syntax
Solution
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".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.Final Answer:
"outputs": { "vmNames": { "type": "array", "value": "[variables('vmNames')]" } } -> Option DQuick Check:
Output array = type array + value in [ ] [OK]
- Using type 'string' for arrays
- Omitting brackets around expressions
- Adding unnecessary array() function
