Functions & Expressions
Use ARM template functions to build dynamic names, references, and values.
Theory
ARM templates use functions inside [ ] expressions to compute values at
deploy time. The ones you’ll meet most:
resourceGroup()/subscription()— deployment context (location, id)parameters()/variables()— pull declared valuesconcat()/format()— build strings (e.g. resource names)uniqueString()— deterministic hash for globally-unique namesreference()/resourceId()— refer to other resources’ runtime props
These let one template adapt to its environment — generating unique storage account names, deriving locations, and wiring resource dependencies dynamically.
Real-World Example
"variables": {
"storageName": "[concat('st', uniqueString(resourceGroup().id))]",
"location": "[resourceGroup().location]"
},
"resources": [{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2023-01-01",
"name": "[variables('storageName')]",
"location": "[variables('location')]",
"sku": { "name": "Standard_LRS" },
"kind": "StorageV2"
}] Hands-On Exercise
- Use
concatanduniqueStringto build a unique storage account name. - Reference the deployment’s location with
resourceGroup().location. - Explain what
reference()retrieves and when you’d use it. - Why is
uniqueStringdeterministic, and why does that matter?
Cheat Sheet▾
| Function | Use |
|---|---|
resourceGroup() | RG context (location, id) |
parameters('x') | Read a parameter |
variables('x') | Read a variable |
concat() / format() | Build strings |
uniqueString() | Deterministic unique hash |
resourceId() | Build a resource ID |
reference() | Read a resource’s runtime props |
Common Interview Questions▾
How do you generate a globally unique resource name in ARM?
Combine a prefix with uniqueString of a stable scope, e.g.
concat('st', uniqueString(resourceGroup().id)) — deterministic, so repeated
deployments produce the same name.
What does the reference() function do?
It retrieves runtime properties of a resource (like an endpoint or key) so you can use values that only exist after a resource is deployed.
Official Documentation
📝 My notes on this topic
Auto-saves as you type