This article describes how to use Azure Resource Manager templates (ARM templates) to tag resources, resource groups, and subscriptions during deployment. For tag recommendations and limitations, see Use tags to organize your Azure resources and management hierarchy.
Note
The tags you apply through an ARM template or Bicep file overwrite any existing tags.
Apply values
The following example deploys a storage account with three tags. Two of the tags (Dept and Environment) are set to literal values. One tag (LastDeployed) is set to a parameter that defaults to the current date.
You can define an object parameter that stores several tags and apply that object to the tag element. This approach provides more flexibility than the previous example because the object can have different properties. Each property in the object becomes a separate tag for the resource. The following example has a parameter named tagValues that's applied to the tag element.
To store many values in a single tag, apply a JSON string that represents the values. The entire JSON string is stored as one tag that can't exceed 256 characters. The following example has a single tag named CostCenter that contains several values from a JSON string:
To apply tags from a resource group to a resource, use the resourceGroup() function. When you get the tag value, use the tags[tag-name] syntax instead of the tags.tag-name syntax, because some characters aren't parsed correctly in the dot notation.
You can add tags to a resource group or subscription by deploying the Microsoft.Resources/tags resource type. You can apply the tags to the target resource group or subscription you want to deploy. Each time you deploy the template you replace any previous tags.
az deployment group create --resource-group exampleGroup --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/tags.json
To apply the tags to a subscription, use either PowerShell or Azure CLI. Deploy to the subscription that you want to tag.
az deployment sub create --name tagresourcegroup --location westus2 --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/tags.json
Manage multiple Azure environment deployments of your JSON Azure Resource Manager templates (ARM templates) by using functions, variables, tags, and parameter files.
Build end-to-end solutions in Microsoft Azure to create Azure Functions, implement and manage web apps, develop solutions utilizing Azure storage, and more.