Tags help to logically organize Azure resources in the environment. It is one of the fundamental principal of good cloud Governance. Each tag consist of a Key and a Value pair. For example, a Key could be “Environment” and corresponding Value is “Development” , or it could be “Application” as Key and “Payroll” as Value.
Microsoft allows you to apply tags on most of azure resource types and Resource Groups. A feature to apply tags on Subscription was a long pending request to Microsoft and the good news is, it is now available! Thank you Microsoft!
Refer following link to know more : https://feedback.azure.com/forums/281804-azure-resource-manager/suggestions/13300434-add-tag-to-subscription?tracking_code=6ed3a1ed74ead6602f12fa3e8b245bb2
As this feature is now available, I will provide you a quick script snippet on how to set that using Powershell. Before starting, you need to install/import latest Az.Resources module on your system. Check current version of your Az.Resources module :
Get-Module -ListAvailable Az.Resources
Now update/install this module with following command :
Update-Module Az.Resources
#Or use Install module command if it is not already installed
Install-Module Az.Resources
Login to your Azure tenant and get Subscription Id on which new tags will be applied.
$subscription = Get-AzSubscription -SubscriptionName <My Subscription Name>
$subscriptionId = $subscription.Id
Now, define a Hash table of tag key/value pairs to be applied on the Subscription
$tags = @{"Environment"="Development"; "Application"="Payroll"}
Finally, apply tags to the subscription with following powershell command :
New-AzTag -ResourceId "/subscriptions/$subscriptionId" -Tag $tags
If you want to update or add tags to existing tags to the subscription, use following command :
Update-AzTag -ResourceId "/subscriptions/$subscriptionId" -Tag $tags -Operation Merge
That’s it! Now you should be able to apply tags to your Subscription.