You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Describes the Azure Policies that you can assign to ensure tag compliance.
4
+
ms.topic: conceptual
5
+
ms.date: 03/18/2020
6
+
---
7
+
8
+
# Assign policies for tag compliance
9
+
10
+
You can use [Azure Policy](../../governance/policy/overview.md) to enforce tagging rules and conventions. By creating a policy, you avoid the scenario of resources being deployed to your subscription that don't comply with the expected tags for your organization. Instead of manually applying tags or searching for resources that aren't compliant, you can create a policy that automatically applies the needed tags during deployment. Tags can also now be applied to existing resources with the new [Modify](../../governance/policy/concepts/effects.md#modify) effect and a [remediation task](../../governance/policy/how-to/remediate-resources.md). The following section shows example policies for tags.
title: Tag resources, resource groups, and subscriptions for logical organization
3
3
description: Shows how to apply tags to organize Azure resources for billing and managing.
4
4
ms.topic: conceptual
5
-
ms.date: 01/03/2020
5
+
ms.date: 03/18/2020
6
6
---
7
-
# Use tags to organize your Azure resources
7
+
# Use tags to organize your Azure resources, resource groups and subscriptions
8
8
9
-
You apply tags to your Azure resources to logically organize them into a taxonomy. Each tag consists of a name and a value pair. For example, you can apply the name "Environment" and the value "Production" to all the resources in production.
9
+
You apply tags to your Azure resources, resource groups, and subscriptions to logically organize them into a taxonomy. Each tag consists of a name and a value pair. For example, you can apply the name "Environment" and the value "Production" to all the resources in production.
10
10
11
-
After you apply tags, you can retrieve all the resources in your subscription with that tag name and value. Tags enable you to retrieve related resources from different resource groups. This approach is helpful when you need to organize resources for billing or management.
11
+
For recommendations on how to implement a tagging strategy, see [Resource naming and tagging decision guide](/azure/cloud-adoption-framework/decision-guides/resource-tagging/?toc=/azure/azure-resource-manager/management/toc.json).
12
12
13
-
Your taxonomy should consider a self-service metadata tagging strategy in addition to an autotagging strategy to reduce the burden on users and increase accuracy.
13
+
You can apply Azure Policies to make sure tagging conventions are maintained for your organization. For more information, see [Assign policies for tag compliance](tag-policies.md).
14
14
15
15
[!INCLUDE [Handle personal data](../../../includes/gdpr-intro-sentence.md)]
16
16
17
-
## Limitations
17
+
## Required access
18
18
19
-
The following limitations apply to tags:
19
+
To apply tags to resources, the user must have write access to that resource type. To apply tags to all resource types, use the [Contributor](../../role-based-access-control/built-in-roles.md#contributor) role. To apply tags to only one resource type, use the contributor role for that resource. For example, to apply tags to virtual machines, use the [Virtual Machine Contributor](../../role-based-access-control/built-in-roles.md#virtual-machine-contributor).
20
20
21
-
* Not all resource types support tags. To determine if you can apply a tag to a resource type, see [Tag support for Azure resources](tag-support.md).
22
-
* Each resource or resource group can have a maximum of 50 tag name/value pairs. If you need to apply more tags than the maximum allowed number, use a JSON string for the tag value. The JSON string can contain many values that are applied to a single tag name. A resource group can contain many resources that each have 50 tag name/value pairs.
23
-
* 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.
24
-
* Generalized VMs don't support tags.
25
-
* Tags applied to the resource group are not inherited by the resources in that resource group.
26
-
* Tags can't be applied to classic resources such as Cloud Services.
27
-
* Tag names can't contain these characters: `<`, `>`, `%`, `&`, `\`, `?`, `/`
21
+
## PowerShell
28
22
29
-
> [!NOTE]
30
-
> Currently Azure DNS zones and Traffic Manger services also don't allow the use of spaces in the tag.
23
+
Azure PowerShell offers two commands for applying tags - [New-AzTag](/powershell/module/az.resources/new-aztag) and [Update-AzTag](/powershell/module/az.resources/update-aztag). You must have Azure PowerShell 3.6.1 or later to use these commands.
31
24
32
-
## Required access
25
+
The **New-AzTag** replaces all tags on the resource, resource group, or subscription. When calling the command, pass in the resource ID of the entity you wish to tag.
33
26
34
-
To apply tags to resources, the user must have write access to that resource type. To apply tags to all resource types, use the [Contributor](../../role-based-access-control/built-in-roles.md#contributor) role. To apply tags to only one resource type, use the contributor role for that resource. For example, to apply tags to virtual machines, use the [Virtual Machine Contributor](../../role-based-access-control/built-in-roles.md#virtual-machine-contributor).
27
+
The following example applies a set of tags to a storage account:
You can use [Azure Policy](../../governance/policy/overview.md) to enforce tagging rules and conventions. By creating a policy, you avoid the scenario of resources being deployed to your subscription that don't comply with the expected tags for your organization. Instead of manually applying tags or searching for resources that aren't compliant, you can create a policy that automatically applies the needed tags during deployment. Tags can also now be applied to existing resources with the new [Modify](../../governance/policy/concepts/effects.md#modify) effect and a [remediation task](../../governance/policy/how-to/remediate-resources.md). The following section shows example policies for tags.
35
+
When the command completes, notice that the resource has two tags.
Every time you apply tags to a resource or a resource group, you overwrite the existing tags on that resource or resource group. Therefore, you must use a different approach based on whether the resource or resource group has existing tags.
90
186
91
187
To add tags to a *resource group without existing tags*, use:
To apply all tags from a resource group to its resources, and *not keep existing tags on the resources*, use the following script:
128
204
@@ -275,7 +351,7 @@ done
275
351
IFS=$origIFS
276
352
```
277
353
278
-
## Templates
354
+
## ARM templates
279
355
280
356
To tag a resource during deployment, add the `tags` element to the resource you're deploying. Provide the tag name and value.
281
357
@@ -436,7 +512,23 @@ You can retrieve information about tags through the [Azure Resource Usage and Ra
436
512
437
513
For REST API operations, see [Azure Billing REST API Reference](/rest/api/billing/).
438
514
515
+
## Limitations
516
+
517
+
The following limitations apply to tags:
518
+
519
+
* Not all resource types support tags. To determine if you can apply a tag to a resource type, see [Tag support for Azure resources](tag-support.md).
520
+
* Each resource or resource group can have a maximum of 50 tag name/value pairs. If you need to apply more tags than the maximum allowed number, use a JSON string for the tag value. The JSON string can contain many values that are applied to a single tag name. A resource group can contain many resources that each have 50 tag name/value pairs.
521
+
* 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.
522
+
* Generalized VMs don't support tags.
523
+
* Tags applied to the resource group are not inherited by the resources in that resource group.
524
+
* Tags can't be applied to classic resources such as Cloud Services.
525
+
* Tag names can't contain these characters: `<`, `>`, `%`, `&`, `\`, `?`, `/`
526
+
527
+
> [!NOTE]
528
+
> Currently Azure DNS zones and Traffic Manger services also don't allow the use of spaces in the tag.
529
+
530
+
439
531
## Next steps
440
532
441
533
* Not all resource types support tags. To determine if you can apply a tag to a resource type, see [Tag support for Azure resources](tag-support.md).
442
-
* For an introduction to using the portal, see [Using the Azure portal to manage your Azure resources](manage-resource-groups-portal.md).
534
+
* For an introduction to using the portal, see [Using the Azure portal to manage your Azure resources](manage-resource-groups-portal.md).
0 commit comments