Working around Azure Tagging Limits – Using JSON formats.

Have you ever ran into the hard-limit in Azure for the amount of tags allowed on asingle resource, or resource group even?
When you work in a large organisation that wants to track everything this mightbe one of the things happening to you.

Let’s dig a bit into the actual limits of tagging currently in azure.
source: https://docs.microsoft.com/en-us/azure/azure-subscription-service-limits

  • Each resource or resource group can have a maximum of 15 tag name/value pairs
  • The tag name is limited to 512 characters
  • 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.
  • Tags can’t be applied to classic resources such as Cloud Services.
  • Tag names can’t contain these characters: <, >, %, &, \, ?, /

So this means we can have a Maximum of 15 tag name/value pairs on a resource/resource group.
This means if you want to tag for example: Owner, Team, Manager, CostCenter, Environment,BackupType, Expirationdate, MaintenanceWindow, etc. You will run out of those tags pretty quickly.

Luckily looking at the rest of the limitations: The tag value is limited to 256 characters! (that is a lot of characters!), and tag names cannot contain a few set of characters.

Since we don’t spot curly braces in the ‘cannotcontain’ list, why not start using JSON in as tag value’s to concatenate tags?

{
“Team”: “Solution Architects”,
“BackupType”: “FullBackup”,
“Manager”: “Danny den Braver”,
“ExpirationDate”: “None”,
“MaintenanceWindow”: {
“Days”: [
“Saturday”,
“Sunday”
],
“Hours”: “12:00-20:00”
},
“Environment”: “Development”,
“Owner”: “Danny den Braver”,
“CostCenter”: “12345”
}

Now let’sput this into practise on how we could do this leveraging powershell(specifically as I like splatting more than writing native JSON)

Let’sfirst build our hashtable and convert it to JSON

$ServerDetails = @{
Owner = ‘Danny den Braver’
Team = ‘Solution Architects’
Manager = ‘Danny den Braver’
CostCenter = ‘12345’
Environment = ‘Development’
BackupType = ‘FullBackup’
ExpirationDate = ‘None’
MaintenanceWindow = @{
Days = ‘Saturday’,’Sunday’
Hours = ’12:00-20:00′
}
}

$ServerDetailsJSON = $ServerDetails | convertto-json

Now we can add it as a tag value to ourenvironment

$Tags = @{
‘ServerDetails’ = $ServerDetailsJSON
}

Set-AzureRmResourceGroup -Name db-personal-rg-01 -Tag $Tags

Thisis what it will look like inside the portal:

Thisis what it will look like from PowerShell:

Hopefullythis will give you enough room for moving ahead using Tags within Azure.




Bedrijfsuitje

Category : Uncategorized

Op 6 oktober 2018 heeft Methos een gezellig bedrijfsuitje mogen beleven. De drie medewerkers, en hun partners, hebben zich ternauwernood weten te redden uit de Mission Impossible escaperoom in Scheveningen. Met nog 1,5 minuut te gaan is de wereld gered, en dit keer niet door automatisering!

Onze wereldverbeteraars hebben daarna wel verdiend genoten van een avond Tasty Comedy op de pier. Danny, bedankt voor het organiseren!