Skip to content

Commit a45fa33

Browse files
committed
Add read tags to the tags article
1 parent 145a045 commit a45fa33

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Tag resources, resource groups, and subscriptions with Bicep
33
description: Shows how to use Bicep to apply tags to Azure resources.
44
ms.topic: conceptual
55
ms.custom: devx-track-bicep
6-
ms.date: 09/26/2024
6+
ms.date: 05/14/2025
77
---
88

99
# Apply tags with Bicep
@@ -136,6 +136,24 @@ resource applyTags 'Microsoft.Resources/tags@2021-04-01' = {
136136
}
137137
```
138138

139+
## Read Tags
140+
141+
You can read existing tags with the following approaches.
142+
143+
> [!WARNING]
144+
> The `tags` property on the `Microsoft.Resources/tags` resource is not set if there are no tags set.
145+
> To avoid errors, ensure you use the safe-dereference operator (`.?`) on `properties`.
146+
147+
```Bicep
148+
resource readTags 'Microsoft.Resources/tags@2021-04-01' existing = {
149+
name: 'default'
150+
}
151+
var tagValue = readTags.properties?.tags?.myTag
152+
153+
// Equivalent to above:
154+
var tagValue2 = reference(subscriptionResourceId('Microsoft.Resources/tags', 'default'), '2021-04-01', 'Full').properties.?tags.?myTag2
155+
```
156+
139157
## Next steps
140158

141159
* For a list of resource types that support tags, see [Tag support for Azure resources](tag-support.md).

0 commit comments

Comments
 (0)