
"$schema"contentVersionparametersvariablesfunctionsresourcesoutputs
"$schema", contentVersion, and resources are required for a valid deployment template. The optional sections (parameters, variables, functions, and outputs) are commonly used to make templates reusable, maintainable, and easier to test.
Required top-level elements include
"$schema", contentVersion, and resources. Add parameters, variables, functions, and outputs to make templates reusable and less error-prone.Schema
The"$schema" property points to the JSON schema that defines the ARM template language version and grammar. The schema URL can vary depending on deployment scope (tenant, management group, subscription, or resource group). Use the schema URL that matches your deployment scope and ARM features.
Example:
contentVersion
contentVersion is a simple version string you can use for tracking template revisions in source control. The convention "1.0.0.0" is frequently used, but you can adopt any versioning scheme that fits your release workflow.
Example:
Parameters
Parameters let you pass values into the template at deployment time. Parameters make templates flexible and reusable across environments (dev/test/prod) without editing the template file. Example parameter definition (validates allowed values, supplies a default, and includes metadata):- If a supplied value is not in
allowedValues, the deployment fails. - If no value is supplied,
defaultValueis used.
Variables
Variables are fixed values declared inside the template and referenced throughout it. Use variables to centralize repeated literals (for example, resource name prefixes, tags, or shared values) so you only update them in one place. Example:variables('publicIPAddressName').
Functions
ARM templates support user-defined functions to encapsulate reusable logic or repeated code patterns. Functions accept parameters and return computed values that can be referenced elsewhere in the template. Example user-defined function that returns a string (typically you would compute names or composite values here):userspace.VMNameGenerator('alice') (using the ARM template expression syntax).
Resources
Theresources array contains all resource objects to be deployed. Each resource object has common properties such as name, type, apiVersion, location, sku (when applicable), tags, and properties. Include every resource you want to create, update, or remove in this array.
Example: deploying an App Service plan (references the location parameter):
- Pin
apiVersionto a specific supported version for predictable behavior. - Use
dependsOnto control creation order where implicit dependencies are not sufficient. - Use copy loops and nested templates for repeating or complex deployments.
Outputs
outputs lets a template return values after deployment (for example, resource IDs, hostnames, or connection strings). Outputs are useful when you need to pass values from one deployment to another or display important information to the user.
Example:
Summary
Structure your ARM template with a clear separation of concerns:"$schema"for grammar/version,contentVersionfor template revision tracking,parametersfor external inputs,variablesfor centralized constants,functionsfor reusable logic,resourcesfor the actual Azure objects, andoutputsfor post-deployment information.
- ARM templates overview: https://learn.microsoft.com/azure/azure-resource-manager/templates/overview
- Template language schema reference: https://learn.microsoft.com/azure/azure-resource-manager/templates/template-syntax
- Azure Resource Manager REST API and
resourceIdfunction: https://learn.microsoft.com/azure/azure-resource-manager/templates/template-functions-resource#resourceid