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
Copy file name to clipboardExpand all lines: articles/azure-resource-manager/management/tag-resources.md
+16-67Lines changed: 16 additions & 67 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,8 +10,6 @@ You apply tags to your Azure resources, resource groups, and subscriptions to lo
10
10
11
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
-
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
-
15
13
[!INCLUDE [Handle personal data](../../../includes/gdpr-intro-sentence.md)]
16
14
17
15
## Required access
@@ -110,10 +108,11 @@ To update the tags for a resource group, use:
To apply all tags from a resource group to its resources, and *not keep existing tags on the resources*, use the following script:
305
-
306
-
```azurecli-interactive
307
-
jsontags=$(az group show --name examplegroup --query tags -o json)
308
-
tags=$(echo $jsontags | tr -d '"{},' | sed 's/: /=/g')
309
-
resourceids=$(az resource list -g examplegroup --query [].id --output tsv)
310
-
for id in $resourceids
311
-
do
312
-
az resource tag --tags $tags --id $id
313
-
done
314
-
```
315
-
316
-
To apply all tags from a resource group to its resources, and *keep existing tags on resources*, use the following script:
275
+
### Inherit tags
317
276
318
-
```azurecli-interactive
319
-
jsontags=$(az group show --name examplegroup --query tags -o json)
320
-
tags=$(echo $jsontags | tr -d '"{},' | sed 's/: /=/g')
277
+
To apply tags from a subscription or resource group to the resources, see [Azure Policies - tags](tag-policies.md).
321
278
322
-
resourceids=$(az resource list -g examplegroup --query [].id --output tsv)
323
-
for id in $resourceids
324
-
do
325
-
resourcejsontags=$(az resource show --id $id --query tags -o json)
326
-
resourcetags=$(echo $resourcejsontags | tr -d '"{},' | sed 's/: /=/g')
327
-
az resource tag --tags $tags$resourcetags --id $id
328
-
done
329
-
```
330
279
331
280
If your tag names or values include spaces, you must take a couple of extra steps. The following example applies all tags from a resource group to its resources when the tags may contain spaces.
0 commit comments