Azure Resource Tags in JSON Format

This is a quick one: We all know that using Azure Resource Tags is a key element in a company’s governance strategy. Tags are used on resources to ensure you stay in control (e.g. to set an owner, department or environment), for cost management (e.g. to configure a cost center or customer) or any other purposes. Resource tags come with some limitations and it’s important to understand those. One of these limitations is the max. number of tags per resource which by the time of writing is 15. Using JSON-formatted tag values can help companies to overcome this limit.

Tags are name/value pairs. A simple trick to store more or more complex values is to use a JSON-formatted string. That allows to store much more tags and also gives you additional flexibility. Let’s use a “CostCenter” tag as a simple example here. Imagine you want to split costs of a resource between 2 or more different cost centers. using tags. You can easily solve this by using a JSON-formatted value and store two cost center objects in an array.

Name: CostCenter

Value: [{“1”: {“CostCenter”: 123,”Percentage”: 80},”2″: {“CostCenter”: 456,”Percentage”: 20}}]

image

Once needed, you can extract the JSON-string and use the name/values from the array in your billing procedure (or for whatever you want to use the data). Using the Azure CLI you can easily access the tags of a resource.

$resource = az resource list –query “[?name==’w-agw-iis-01′]” | convertfrom-json

image

$resource.tags.costcenter | convertfrom-json

($resource.tags.costcenter | convertfrom-json).1

image

Happy tagging!
Cheers, Marcel

About Marcel Zehner

Microsoft Azure MVP
This entry was posted in Azure and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s