Skip to content

Commit 2aec23a

Browse files
committed
update
1 parent 4d833bf commit 2aec23a

File tree

4 files changed

+52
-37
lines changed

4 files changed

+52
-37
lines changed

articles/azure-resource-manager/management/tag-resources.md

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Properties :
7676
Environment Production
7777
```
7878

79-
If you provide a new value for a tag and use the merge operation, the old value is replaced. The following example changes the Status tag from Normal to Green.
79+
Each tag name can have only one value. If you provide a new value for a tag, the old value is replaced even if you use the merge operation. The following example changes the Status tag from Normal to Green.
8080

8181
```azurepowershell-interactive
8282
$tags = @{"Status"="Green"}
@@ -129,16 +129,6 @@ $resourceGroup = Get-AzResourceGroup -Name demoGroup
129129
Update-AzTag -ResourceId $resourceGroup.ResourceId -Tag $tags -Operation Merge
130130
```
131131

132-
```output
133-
Properties :
134-
Name Value
135-
=========== ==========
136-
CostCenter 00123
137-
Environment Production
138-
Status Normal
139-
Dept Finance
140-
```
141-
142132
To add a new set of tags to a subscription, use:
143133

144134
```azurepowershell-interactive
@@ -155,15 +145,6 @@ $subscription = (Get-AzSubscription -SubscriptionName "Example Subscription").Id
155145
Update-AzTag -ResourceId "/subscriptions/$subscription" -Tag $tags -Operation Merge
156146
```
157147

158-
```output
159-
Properties :
160-
Name Value
161-
=========== ========
162-
Environment Dev
163-
CostCenter 00123
164-
Team Web Apps
165-
```
166-
167148
You may have more than one resource with the same name in a resource group. In that case, you can set each resource with the following commands:
168149

169150
```azurepowershell-interactive
@@ -173,11 +154,11 @@ $resource | ForEach-Object { Update-AzTag -Tag @{ "Dept"="IT"; "Environment"="Te
173154

174155
### Inherit tags
175156

176-
To apply tags from a subscription or resource group to the resources, see [Azure Policies - tags](tag-policies.md).
157+
Tags applied to the resource group or subscription aren't inherited by the resources. To apply tags from a subscription or resource group to the resources, see [Azure Policies - tags](tag-policies.md).
177158

178159
### List tags
179160

180-
To get the tags for a resource, resource group, or subscription, use the [Get-AzTag](/powershell/module/az.resources/get-aztag) command and pass in the entity.
161+
To get the tags for a resource, resource group, or subscription, use the [Get-AzTag](/powershell/module/az.resources/get-aztag) command and pass in the resource ID for the entity.
181162

182163
To see the tags for a resource, use:
183164

@@ -279,7 +260,7 @@ Currently, Azure CLI doesn't support applying tags to subscriptions.
279260

280261
### Inherit tags
281262

282-
To apply tags from a subscription or resource group to the resources, see [Azure Policies - tags](tag-policies.md).
263+
Tags applied to the resource group or subscription aren't inherited by the resources. To apply tags from a subscription or resource group to the resources, see [Azure Policies - tags](tag-policies.md).
283264

284265
### List tags
285266

@@ -338,17 +319,21 @@ IFS=$origIFS
338319

339320
## ARM templates
340321

341-
You can tag resources, resource groups, and subscriptions during deployment with an ARM template.
322+
You can tag resources, resource groups, and subscriptions during deployment with an ARM template.
342323

343-
### Apply literal values
324+
### Apply values
344325

345-
The following example deploys a storage account with two tags (`Dept` and `Environment`) that are set to literal values:
326+
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.
346327

347328
```json
348329
{
349330
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
350331
"contentVersion": "1.0.0.0",
351332
"parameters": {
333+
"utcShort": {
334+
"type": "string",
335+
"defaultValue": "[utcNow('d')]"
336+
},
352337
"location": {
353338
"type": "string",
354339
"defaultValue": "[resourceGroup().location]"
@@ -362,7 +347,8 @@ The following example deploys a storage account with two tags (`Dept` and `Envir
362347
"location": "[parameters('location')]",
363348
"tags": {
364349
"Dept": "Finance",
365-
"Environment": "Production"
350+
"Environment": "Production",
351+
"LastDeployed": "[parameters('utcShort')]"
366352
},
367353
"sku": {
368354
"name": "Standard_LRS"
@@ -374,11 +360,9 @@ The following example deploys a storage account with two tags (`Dept` and `Envir
374360
}
375361
```
376362

377-
To set a tag to a datetime value, use the [utcNow function](../templates/template-functions-string.md#utcnow).
378-
379363
### Apply an object
380364

381-
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 any properties. Each property in the object becomes a separate tag for the resource. The following example has a parameter named `tagValues` that is applied to the tag element.
365+
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 is applied to the tag element.
382366

383367
```json
384368
{
@@ -536,6 +520,36 @@ New-AzSubscriptionDeployment -name tagresourcegroup -Location westus2 -TemplateU
536520
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
537521
```
538522

523+
The following template adds the tags from an object to either a resource group or subscription.
524+
525+
```json
526+
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
527+
"contentVersion": "1.0.0.0",
528+
"parameters": {
529+
"tags": {
530+
"type": "object",
531+
"defaultValue": {
532+
"TeamName": "AppTeam1",
533+
"Dept": "Finance",
534+
"Environment": "Production"
535+
}
536+
}
537+
},
538+
"variables": {},
539+
"resources": [
540+
{
541+
"type": "Microsoft.Resources/tags",
542+
"name": "default",
543+
"apiVersion": "2019-10-01",
544+
"dependsOn": [],
545+
"properties": {
546+
"tags": "[parameters('tags')]"
547+
}
548+
}
549+
]
550+
}
551+
```
552+
539553
## Portal
540554

541555
[!INCLUDE [resource-manager-tag-resource](../../../includes/resource-manager-tag-resources.md)]
@@ -560,7 +574,6 @@ The following limitations apply to tags:
560574
* 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.
561575
* 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.
562576
* Generalized VMs don't support tags.
563-
* Tags applied to the resource group are not inherited by the resources in that resource group.
564577
* Tags can't be applied to classic resources such as Cloud Services.
565578
* Tag names can't contain these characters: `<`, `>`, `%`, `&`, `\`, `?`, `/`
566579

27.7 KB
Loading
29.2 KB
Loading

includes/resource-manager-tag-resources.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
author: tfitzmac
66
ms.service: azure-resource-manager
77
ms.topic: include
8-
ms.date: 01/03/2020
8+
ms.date: 03/19/2020
99
ms.author: tomfitz
1010
ms.custom: include file
1111
---
1212

1313
1. To view the tags for a resource or a resource group, look for existing tags in the overview. If you have not previously applied tags, the list is empty.
14-
15-
![View tags for resource or resource group](./media/resource-manager-tag-resources/view-tags.png)
14+
15+
![View tags for resource or resource group](./media/resource-manager-tag-resources/view-tags.png)
16+
1617
1. To add a tag, select **Click here to add tags**.
1718

18-
1. Provide a name and value. Select **+** to add the tag.
19-
20-
![Add tag](./media/resource-manager-tag-resources/add-tag.png)
19+
1. Provide a name and value.
20+
21+
![Add tag](./media/resource-manager-tag-resources/add-tag.png)
22+
2123
1. Continue adding tags as needed. When done, select **Save**.
2224

2325
![Save tags](./media/resource-manager-tag-resources/save-tags.png)

0 commit comments

Comments
 (0)