- Article
- 16 minutes to read
Tags are metadata elements that you apply to your Azure resources. They are key-value pairs that help you identify features based on configurations relevant to your organization. If you want to control the deployment environment of your resources, include a key called Environment. To identify production-ready resources, assign them the value Production. The key-value pair for Environment = Production is fully formed.
You can apply tags to your Azure resources, resource groups, and subscriptions.
For recommendations on how to implement a tagging strategy, seeDecision support for resource naming and labeling.
Resource tags support all paid services. To ensure paid services are branded, use one of theetiquette guidelines.
embargo
Tags are stored as plain text. Never add sensitive values to tags. Sensitive values can be exposed through a variety of methods, including cost reports, commands that return existing tag definitions, deployment histories, exported templates, and audit logs.
Important
In operations, tag names are not case sensitive. A tag with a tag name is updated or retrieved regardless of case. However, the resource provider can preserve the case specified for the tag name. You will see this case in cost reports.
Label values are case sensitive.
Use
This article provides steps to remove personal data from your device or service and can be used to support your obligations under the GDPR. You can find general information about the GDPR atMicrosoft Trust Center GDPR sectionit's himGDPR section of the Service Trust portal.
required access
There are two ways to get the access you need to tag resources.
Has write access to
Microsoft.Recursos/Tags
resource type. With this access, you can tag any resource, even if you don't have access to the resource itself. Thelabel contributorThe role grants this access. For example, the Tag Contributor role cannot apply tags to resources or groups of resources through the portal. However, you can apply tags to signatures through the portal. Supports all tag operations through Azure PowerShell and REST API.You can have write access to the resource itself. ThecontributorThe role grants the necessary access to apply labels to any entity. To apply tags to just one type of resource, use the Contributor role for that resource. For example, to apply tags to virtual machines, use theVirtual Machine Contributor.
Power Shell
apply labels
Azure PowerShell provides two commands to apply labels:New-AzTagyUpdate-AzTag. you must have itthe resources
Module version 1.12.0 or higher. You can check your version withGet-InstalledModule -Nombre Az.Resources
. You can install this module orInstall Azure PowerShellVersion 3.6.1 or higher.
DieNew-AzTag
replaces any tag for the resource, resource group, or subscription. When invoking the command, pass the resource ID of the entity you want to tag.
The following example applies a defined tag to a storage account:
$tags = @{"Departamento"="Finanças"; "Status"="Normal"}$resource = Get-AzResource -Name demoStorage -ResourceGroup demoGroupNew-AzTag -ResourceId $resource.id -Tag $tags
After the command completes, notice that the resource has two tags.
Properties: Name Value ====== ====== Financial Department Status Normal
If you run the command again, but this time with different labels, you'll notice that the old labels disappear.
$tags = @{"Team"="Compliance"; "Environment"="Production"}New-AzTag -ResourceId $resource.id -Tag $tags
Properties: Name Value ============ ========= Environment Conformity of production equipment
Use it to add tags to a resource that already has tagsUpdate-AzTag
. define those-Operation
parameters tojoin
.
$tags = @{"Departamento"="Finanças"; "Status"="Normal"}Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge
Notice that the existing tags grow as the two new tags are added.
Properties: Name Value ============ ========= Status Normal Financial Department Team Compliance Environment Production
Each tag name can have only one value. If you specify a new value for a tag, it will replace the old value even if you use the merge operation. The following example changes thestate
day ofNormalanverde.
$tags = @{"Status"="Green"}Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge
Properties: Nombre Value ==== === Estado Green Dept Finance Team Compliance Environment Production
When configuring the-Operation
parameters toSubstitute
, the new set of tags will replace the existing tags.
$tags = @{"Projeto"="E-commerce"; "Centro de Custo"="00123"; "Team"="Web"}AzTag-Update -ResourceId $resource.id -Tag $tags -Operation Replace
Only new tags remain on the resource.
Properties: Name Value ========= ========= CostCenter 00123 Team Web Project ECommerce
The same commands also work with resource groups or subscriptions. Pass them in the ID of the resource group or subscription you want to tag.
To add a new set of tags to a resource group, use:
$tags = @{"Departamento"="Finanças"; "Status"="Normal"}$resourceGroup = Get-AzResourceGroup -Name demoGroupNew-AzTag -ResourceId $resourceGroup.ResourceId -tag $tags
To update tags for a resource group, use:
$etiquetas = @{"CostCenter"="00123"; "Entorno"="Produção"}$resourceGroup = Get-AzResourceGroup -Name demoGroupUpdate-AzTag -ResourceId $resourceGroup.ResourceId -Tag $tags -Operation Merge
To add a new set of tags to a signature, use:
$etiquetas = @{"CostCenter"="00123"; "Environment"="Dev"}$subscription = (Get-AzSubscription -SubscriptionName "Beispielabonnement").IdNew-AzTag -ResourceId "/subscriptions/$subscription" -Tag $tags
To update labels for a subscription usage:
$tags = @{"Team"="Web Apps"}$subscription = (Get-AzSubscription -SubscriptionName "Ejemplo de assinatura").IdUpdate-AzTag -ResourceId "/subscriptions/$subscription" -Tag $tags -Operation Merge
You can have more than one resource with the same name in a resource group. In that case, you can configure each feature with the following commands:
$resource = Get-AzResource -ResourceName sqlDatabase1 -ResourceGroupName grupo de amostra $resource | ForEach-Object { Update-AzTag -Tag @{ "Dept"="IT"; "Ambiente"="Teste" } -ResourceId $_.ResourceId -merge operation }
list labels
To get the tags for a resource, resource group, or subscription, use theGet AzTagcommand and pass the entity resource ID.
To view a resource's usage labels:
$recurso = Get-AzResource -Name demoStorage -ResourceGroup demoGroupGet-AzTag -ResourceId $resource.id
To view the tags for a resource group, use:
$resourceGroup = Get-AzResourceGroup -Name demoGroupGet-AzTag -ResourceId $resourceGroup.ResourceId
To view a subscription's usage labels:
$subscription = (Get-AzSubscription -SubscriptionName "Beispielabonnement").IdGet-AzTag -ResourceId "/subscriptions/$subscription"
list per day
To get resources with a specific name and tag value, use:
(Get-AzResource-Tag @{ "CostCenter"="00123"}).Name
To get resources that have a specific tag name with any tag value, use:
( Get - AzResource - TagName "Dept").Name
To get groups of resources with a specific name and tag value, use:
(Get-AzResourceGroup -Tag @{ "CostCenter"="00123" }).ResourceGroupName
remove favorites
To remove specific tags, useUpdate-AzTag
and adjust-Operation
anextinguish
. Pass the resource IDs of the tags you want to remove.
$removeTags = @{"Project"="E-commerce"; "Team"="Web"}Update-AzTag -ResourceId $resource.id -Tag $removeTags -Remover tarefa
The specified tags will be removed.
Properties: Name Value ======== ===== CostCenter 00123
To remove all tags, use theRemover-AzTagDomain.
$subscription = (Get-AzSubscription -SubscriptionName „Beispielabonnement“).IdRemove-AzTag -ResourceId „/subscriptions/$subscription“
CLI do Azure
apply labels
Azure CLI provides two commands to apply tags:Create a-z labelythe member update. You need Azure CLI version 2.10.0 or higher. You can check your version withblue version
. To update or install, seeInstale a CLI do Azure.
DieCreate a-z label
replaces any tag for the resource, resource group, or subscription. When invoking the command, pass the resource ID of the entity you want to tag.
The following example applies a defined tag to a storage account:
resource=$(az resource show -g demoGroup -n demoStorage --resource-type Microsoft.Storage/storageAccounts --query "id" --output tsv)az tag create --resource-id $resource --tags Dept=Finanzas Estado=Normal
After the command completes, notice that the resource has two tags.
"properties": { "labels": { "Dept": "Financial", "Status": "Normal" }},
If you run the command again, but this time with different labels, you'll notice that the old labels disappear.
az tag create --resource-id $resource --tags Team=Compliance environment=Production
"properties": { "tags": { "Environment": "Production", "Equipment": "Compliance" }},
Use it to add tags to a resource that already has tagsthe member update
. define those--Operation
parameters tojoin
.
update az tag --resource-id $resource --merge operation --tags Dept=Financial Status=Normal
Notice that the existing tags grow as the two new tags are added.
"properties": { "tags": { "Dept": "Finance", "Environment": "Production", "Status": "Normal", "Equipment": "Compliance" }},
Each tag name can have only one value. If you specify a new value for a tag, the new tag will replace the old value, even if you use the merge operation. The following example changes thestate
day ofNormalanverde.
az tag update --resource-id $resource --operation Merge --tags Status=Grün
"properties": { "tags": { "Dept": "Finance", "Environment": "Production", "State": "Green", "Equipment": "Compliance" }},
When configuring the--Operation
parameters toSubstitute
, the new set of tags will replace the existing tags.
update az tag --resource-id $resource --operation Replace --tags Project=ECommerce CostCenter=00123 Team=Web
Only new tags remain on the resource.
"properties": { "tags": { "CostCenter": "00123", "Project": "Ecommerce", "Team": "Web" }},
The same commands also work with resource groups or subscriptions. Pass them in the ID of the resource group or subscription you want to tag.
To add a new set of tags to a resource group, use:
group=$(az group show -n demoGroup --query id --output tsv)az tag create --resource-id $group --tags Dept=Finance Status=Normal
To update tags for a resource group, use:
az tag update --resource-id $group --operation Merge --tags CostCenter=00123 Environment=Production
To add a new set of tags to a signature, use:
sub=$(mostrar conta az --subscription "Demo Subscription" --query id --output tsv) criar tag az --resource-id /subscriptions/$sub --tags CostCenter=00123 Environment=Dev
To update labels for a subscription usage:
az tag update --resource-id /subscriptions/$sub --operation Merge --tags Team="Web Apps"
list labels
To get the tags for a resource, resource group, or subscription, use thelista de tags azcommand and pass the entity resource ID.
To view a resource's usage labels:
resource=$(az resource show -g demoGroup -n demoStorage --resource-type Microsoft.Storage/storageAccounts --query "id" --output tsv)az tag list --resource-id $resource
To view the tags for a resource group, use:
group=$(az group show -n demoGroup --query id --output tsv)az tag list --resource-id $group
To view a subscription's usage labels:
sub=$(mostrar conta az --subscription "Demo Subscription" --query id --output tsv)list tags az --resource-id /subscriptions/$sub
list per day
To get resources with a specific name and tag value, use:
az resource list --tag CostCenter=00123 --query [].name
To get resources that have a specific tag name with any tag value, use:
resource list az --tag Team --query [].name
To get groups of resources with a specific name and tag value, use:
group list az --tag Dept=Finance
remove favorites
To remove specific tags, usethe member update
and adjust--Operation
anextinguish
. Pass the resource ID of the tags you want to remove.
atualize a tag az --resource-id $resource --operation Excluir --tags Project=Ecommerce Team=Web
You have removed the specified tags.
"properties": { "labels": { "CostCenter": "00123" }},
To remove all tags, use thedelete memberDomain.
az-Tag delete --resource-id $recurso
dealing with spaces
If your tag names or values contain spaces, enclose them in quotes.
update tag az --resource-id $group --Merge operation --tags "Cost Center"=Finance-1222 Location="West US"
plantillas ARM
You can tag resources, resource groups, and subscriptions with an ARM template during deployment.
Use
Tags applied via an ARM template or biceps file will replace existing tags.
apply values
The following example provisions a storage account with three tags. Two of the tags (about
ySurroundings
) are defined as literal values. One day (last implemented
) is defined as a parameter which defaults to the current date.
- JSON
- biceps
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "utcShort ": { "type": "string", "default": "[utcNow('d')]" }, "location": { "type": "string", "default": "[grupo de recursos( ). location]" } }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2021-04-01", "name": "[concat('storage ', string única( resourceGroup().id))]", "location": "[params('location')]", "sku": { "name": "Standard_LRS" }, "type": "Storage", "tags" : { "Dept": "Finanças", "Ambiente": "Produção", "LastDeployed": "[parameters('utcShort')]" }, "propriedades": {} } ]}
apply an object
You can define an object parameter that stores multiple tags and apply that object to the tag element. This approach offers more flexibility than the previous example because the object can have different properties. Each property on the object becomes a separate tag for the resource. The following example has a parameter calledtag values
applied to the tag element.
- JSON
- biceps
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location ": { "type": "string", "defaultValue": "[resourceGroup().location]" }, "tagValues": { "type": "object", "defaultValue": { "Dept": "Finanças ", "Environment": "Production" } } }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2021-04-01", "name": "[concat ('storage', uniquestring(resourceGroup().id))]", "location": "[params('location')]", "sku": { "name": "Standard_LRS" }, "type": "Speech", "tags": "[parameters('tagValues')]", "properties": {} } ]}
Apply a JSON string
To store many values in a single tag, apply a JSON string representing the values. The entire JSON string is stored as a tag that cannot exceed 256 characters. The following example has a single tag calledcost center
containing multiple values of a JSON string:
- JSON
- biceps
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location ": { "type": "string", "defaultValue": "[resourceGroup().location]" } }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": " 2021-04-01", "name": "[concat('storage', uniqueString(resourceGroup().id))]", "location": "[params('location')]", "sku": { "name": "Standard_LRS" }, "kind": "Storage", "tags": { "CostCenter": "{\"Dept\":\"Finanças\",\"Ambiente\":\" Produção \"}" }, "Eigenschaften": {} } ]}
Apply resource group tags
To apply tags from a resource group to a resource, use theresourcegroup()Occupation. If you get the tag value, use theTags[Tag-Name]
syntax instead oftags.nome-tag
Syntax why some characters in dot notation are not parsed correctly.
- JSON
- biceps
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "location ": { "type": "string", "defaultValue": "[resourceGroup().location]" } }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": " 2021-04-01", "name": "[concat('storage', uniqueString(resourceGroup().id))]", "location": "[params('location')]", "sku": { "name": "Standard_LRS" }, "kind": "Storage", "tags": { "Dept": "[resourceGroup().tags['Dept']]", "Environment": "[resourceGroup( ).tags['Umgebung']]" }, "Eigenschaften": {} } ]}
Applying tags to groups of resources or subscriptions
You can add tags to a resource group or subscription by providing theMicrosoft.Recursos/Tags
resource type. You can apply the tags to the target resource group or subscription you want to deploy. Every time you deploy the template, replace the old tags.
- JSON
- biceps
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parámetros": { "tagName ": { "type": "string", "defaultValue": "TeamName" }, "tagValue": { "type": "string", "defaultValue": "AppTeam1" } }, "resources": [ { " type": "Microsoft.Resources/tags", "name": "predeterminado", "apiVersion": "2021-04-01", "properties": { "tags": { "[parámetros('tagName')] ": "[parámetro('tagValue')]" } } } ]}
To apply tags to a resource group, use Azure PowerShell or the Azure CLI. Publish them to the resource group you want to tag.
New-AzResourceGroupDeployment -ResourceGroupName exampleGroup -TemplateFile https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/tags.json
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 tags to a subscription, use PowerShell or the Azure CLI. Provide the signature you want to tag.
New-AzSubscriptionDeployment -name tagresourcegroup -Ubicación westus2 -TemplateUri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/tags.json
az deployment subcreation --name tagresourcegroup --location westus2 --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/tags.json
For more information on signature implementations, seeCreate resource groups and subscription-level resources.
The following template adds an object's tags to a resource group or subscription.
- JSON
- biceps
{ "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "tags ": { "type": "object", "defaultValue": { "TeamName": "AppTeam1", "Dept": "Finanças", "Ambiente": "Produção" } } }, "recursos": [ { " type": "Microsoft.Resources/tags", "apiVersion": "2021-04-01", "name": "default", "properties": { "tags": "[parameters('tags')]" } } ]}
Portal
If a user does not have the necessary access to apply tags, they can assign themlabel contributorfunction for the user. For more information, seeTutorial: Grant a user access to Azure resources using RBAC and the Azure portal.
To view the tags for a resource or group of resources, browse the existing tags in the overview. If you haven't previously applied tags, the list will be empty.
To add a tag, selectClick here to add tags.
Provide a name and value.
Add more tags as needed. When finished, selectsave not computer.
Tags are now displayed in the overview.
See AlsoOverview of Azure Network Security GroupsPost Group Settings – Business CenterAdditional group-based licensing scenarios - Azure AD - Microsoft EnterTo add or remove a tag, selectchange.
To delete a tag, select the trash can icon. then selectsave not computer.
To assign tags to multiple resources at once:
In any list of resources, select the checkbox for the resources you want to tag. then selectassign tags.
Add names and values. When finished, selectsave not computer.
To see all resources with a tag:
Search in the Azure portal menukey words. Select it from the available options.
Select the tag to view the features.
All resources with that tag are displayed.
API REST
To work with tags via the Azure REST API, use:
- Tags: create or update in scope(PUT operation)
- Tags: scope update(PATCH operation)
- Tags - Get Reach(GET operation)
- Tags - Exclude in Scope(Operation DELETE)
SDK
For examples of how to apply tags using the SDK, see:
Resources do not inherit tags that you assign to a resource group or subscription. For information on applying subscription or resource group tags to resources, seeAzure Policies - Tags.
Labels and Billing
You can use tags to group your billing data. For example, if you run multiple virtual machines for different organizations, use tags to group usage by cost center. You can also use tags to categorize costs by runtime environment, such as B. Billing usage for virtual machines running in the production environment.
You can obtain information about tags by downloading the usage file available on the Azure portal. For more information, seeDownload or view your Azure bill and daily usage data. For services that support billing labels, the labels appear in thekey wordsPilar.
For information about REST API operations, seeAzure Billing REST API reference.
limitations
The following restrictions apply to tags:
Not all resource types support tags. See if you can apply a tag to a resource typeBranded support for Azure resources.
Each resource, resource group, and subscription can have a maximum of 50 tag name/value pairs. If you need to apply more tags than the maximum allowed, use a JSON string for the tag value. The JSON string can contain many of the values that you apply to a single tag name. A resource group or subscription can contain many resources, each with 50 pairs of tag name values.
The tag name is limited to 512 characters and the tag value is limited to 256 characters. For storage accounts, the tag name is limited to 128 characters and the tag value is limited to 256 characters.
Classic resources like cloud services don't support tags.
Azure IP groups and Azure firewall policies do not support PATCH operations. Therefore, PATCH API method operations cannot update tags through the portal. Instead, you can use update commands for these features. With you can eg. B. Update labels for an IP poolupdated az network ip groupDomain.
Tag names cannot contain these characters:
<
,>
,%
,&
,\
,?
,/
Use
Azure Domain Name System (DNS) zones don't support the use of spaces in the label or a label that starts with a number. Azure DNS label names don't support special characters or Unicode. The value can contain any characters.
Traffic Manager does not support the use of spaces,
#
o:
in the tag name. The tag name cannot start with a number.Azure Front Door does not support the use of
#
o:
in the tag name.The following Azure resources only support 15 tags:
- blue automation
- Azure Content Delivery Network (CDN)
- Azure DNS (zone and A records)
- Azure Log Analytics Saved Search
Next steps
- Not all resource types support tags. See if you can apply a tag to a resource typeBranded support for Azure resources.
- For recommendations on how to implement a tagging strategy, seeDecision support for resource naming and labeling.