How Do I Make Azure Tag

How Do I Make Azure Tag

In this Azure tutorial, we will discuss How Do I Make Azure Tag. Along with this, we will also discuss the below topics.

  • What Is A Tag In Azure?
  • Why Use The Azure tag?
  • How To Create Azure Tags Using Azure Portal?
  • Azure Tags PowerShell
  • Azure Tags Azure CLI
  • Azure Tag Policy
  • Azure Tagging Best Practices

How Do I Make Azure Tag

Now, before we discuss how do I make Azure tag, Let’s discuss the Overview of the Azure Tag and why use the Azure tag? etc.

What Is A Tag In Azure?

Azure tagging is an excellent feature from Microsoft that introduced recently that can help you to logically group your Azure resources and help you to track your resources. It also helps to automate the deployments of the resources and another important feature is this feature helps to provide the visibility of the resource costs that they are liable for.

The Azure Tag enables the key: value pairs to be created and assigned to the resources in Azure using Azure Portal, PowerShell. Azure CLI, etc.

Along with the Azure resources, you can also use Azure tags to organize the Azure resource groups and the Azure Subscriptions.

Note: Tag names and Tag Values are case-sensitive in nature.

Why Use The Azure tag?

The main intention to use the Azure tags is to organize the resources in Azure Portal. When you are organizing the resources properly that helps you to identify the category that the resources belong to. So basically, Azure tags are the name-value pairs that help to organize the Azure resources in the Azure Portal.

When you have more resources in your Azure Portal, that time it really helps you to categories your Azure Resources. If you will take an example here, Suppose you have 8 Virtual machines (VM) in your Azure Subscription. From the 8 virtual machines, 2 are under our development environment and 2 are for the QA environment and the next 2 belongs to our Production environment. So we can tag them like Environment – Development, Environment – QA, or Environment – Production. Now we can easily get the view of each resource coming under the specific environment.

If you will analyze your detailed Azure usage report, you will find the entry for the tags you assigned for your Azure resources.

Now coming back to our main point, How Do I Make Azure Tag, Well let’s discuss on that.

The first thing is you need the Write access to the Azure resource in order to apply the Azure tag for that resource. Make sure you have to write access before trying to create the Azure tag.

There are multiple ways to create the Azure tag in the Azure Portal. Let’s discuss here, How Do I Make Azure Tag using Azure Portal, PowerShell.

How To Create Azure Tags Using Azure Portal

We can create Azure Tags using the Azure Portal. So let’s discuss How To Create Azure Tags Using Azure Portal. Follow the below steps to create or apply the Azure tag.

Step-1: Login to Azure Portal (https://portal.azure.com/)

Step-2: Navigate to the Resource group for which one you want to create the Azure tag.

Step-3: On the resource group page, if you can see the Overview tab, See the Tags (Change) option, Now click on the Click here to add tags link to add the tags.

How Do I create Azure Tag

Step-4: You can provide the name and value for the tag like below.

How Do I Make Azure Tag using Azure Portal

Step-5: You can keep on adding the name and value, if you want more tags and then click on the Save button to save the changes.

How To Create Azure Tags Using Azure Portal

You can see here it added the assigned tags successfully with out any issues.

Create Azure Tags Using Azure Portal

Step-6: If you will see the Overview tab of the resource group, you can see the tags are getting displayed.

azure tags multiple values

Step-7: if you want to add a new tag or you want to delete an existing tag you can click on the Change link.

Step-8: Click on the delete icon now to delete a tag and then click on the save button to save the changes..

How To delete Azure Tags Using Azure Portal

Assign Tags To Multiple Resources

You can assign tags to multiple resources at a time using Azure Portal.

Select all the lists of resources and then click on the Assign tags button from the top menu.

Create Azure Tags Azure Portal

Add the names and values on the Assign tags window and then click on the Save button.

Create Azure Tags in Azure Portal

You can see below it is Successfully assigned the tag to all the three resources.

How to Create Azure Tags in Azure Portal

View All Resources With A Tag

If you want to view all the tags in Azure Portal.

Search for the Tag in the Azure Portal and click on the Search result Tags.

View All Resources With A Tag

You can click on the each tag below to see the corresponding resources.

View All Resources With A Tag in Azure Portal

Now for example, If you will click on the TSINFO : IT and you can see it showed me all the resources that belong to this tag.

View All Resources With A Tag using Azure Portal

This how you can create Azure Tags Using Azure Portal by following the above steps.

Azure Tags PowerShell

We can create the Azure tag for the Azure resources using PowerShell.

Basically, there are two PowerShell commands i.e New-AzTag and Update-AzTag that can be use to create and update the Azure tags for the Azure resources.

As prerequisites what we need is you need to have Az.Resources module 1.12.0 or the later version or You can install the Azure PowerShell version 3.6.1 or the later version.

Let’s see an example

$mynewtags = @{"TSINFO"="IT"; "Status"="Startup"}
$resourceDetails = Get-AzResource -Name mynewstoragedemo -ResourceGroup newresgroup
New-AzTag -ResourceId $resourceDetails.id -Tag $mynewtags 

If you run the command again with the different tags this time, you will get the new name and value for the tags in Azure.

$mynewtags = @{"TSINFONEW"="ITS"; "Status2"="Startup2"}
$resourceDetails = Get-AzResource -Name mynewstoragedemo -ResourceGroup newresgroup
New-AzTag -ResourceId $resourceDetails.id -Tag $mynewtags 

You can use command Update-AzTag to add tags to the resources that already has tags. You can Set the  – Operation parameter to Merge

$mynewtags = @{"TSINFONEW"="ITSE"; "Status3"="Startup3"}
$resourceDetails = Get-AzResource -Name mynewstoragedemo -ResourceGroup newresgroup
Update-AzTag -ResourceId $resourceDetails.id -Tag $mynewtags -Operation Merge

You can add the set of Azure tags for a Resource Groups using the below cmdlets.

$mynewtags = @{"TSINFONEW"="ITSE"; "Status"="Startup"}
$resourceDetails = Get-AzResourceGroup -Name newresgroup
New-AzTag -ResourceId $resourceDetails.ResourceId -Tag $mynewtags

Same way, you can update the tags for the resource group using the below PowerShell cmdlet.

$mynewtags = @{"TSINFOTECH"="ITS"; "Status01"="Startupnew"}
$resourceDetails = Get-AzResourceGroup -Name newresgroup
Update-AzTag -ResourceId $resourceDetails.ResourceId -Tag $mynewtags

If you want to use a new set of tags to a subscription then you can use the below PowerShell cmdlet.

$mynewtags = @{"NewDept"="ITS"; "Design"="Android"}
$mysubscription = (Get-AzSubscription -SubscriptionName "Mention your Subscription Name").Id
New-AzTag -ResourceId "/subscriptions/$mysubscription" -Tag $mynewtags

Same way, you can update a new set of Azure tag for the subscription using the below PowerShell cmdlet.

$mynewtags = @{"Dept"="HR"}
$mysubscription = (Get-AzSubscription -SubscriptionName "Mention your Subscription Name").Id
Update-AzTag -ResourceId "/subscriptions/$mysubscription" -Tag $mynewtags -Operation Merge

If you want to retrieve the tags for a particular resource, you can use the below PowerShell cmdlet

$resourcedetails = Get-AzResource -Name resourcename -ResourceGroup newresgroup
Get-AzTag -ResourceId $resourcedetails.id

Same way, if you want to retrieve the tags for a resource group then you can use the below PowerShell cmdlet.

$resourcegroupdetails = Get-AzResource -ResourceGroup newresgroup
Get-AzTag -ResourceId $resourcegroupdetails.id

If you want to see the tags for a subscription, you can use the below PowerShell cmdlet

$mysubscription = (Get-AzSubscription -SubscriptionName "Your Subscription name").Id
Get-AzTag -ResourceId "/subscriptions/$mysubscription "

You can use below PowerShell cmdlet if you want to retrieve resources that have a specific tag name and value

(Get-AzResource -Tag @{ "NewDept"="ITS"}).Name

If you want to get the resources that have a specific tag name with any tag value, you can use the below PowerShell cmdlet.

(Get-AzResource -TagName "Design").Name

If you want remove specific tag then you can use the below PowerShell cmdlet

$DeleteTags = @{"TSINFOTECH"="ITS"; "Status01"="Startupnew"}
$resourcedetails = Get-AzResource -Name resourcename -ResourceGroup newresgroup
Update-AzTag -ResourceId $resourcedetails.id -Tag $DeleteTags -Operation Delete

To remove all tags for the subscription, you can use the below PowerShell cmdlet

$mysubscription = (Get-AzSubscription -SubscriptionName "Mention your Subscription Name").Id
Remove-AzTag -ResourceId "/subscriptions/$mysubscription"

This is all about Azure Tags PowerShell. You can use the above PowerShell cmdlets to create the Azure Tags.

Azure Tags Azure CLI

We can also use Azure CLI to create Azure tags or apply the Azure tags. Let’s see the different Azure CLI scripts to create the Azure tags or apply the Azure tags.

Use the below Azure CLI scripts to overwrite the tags on a resource

az resource tag --tags 'TSinfo=HR' 'Technology=Android' -g newresgroup -n DemoStorage --resource-type "Microsoft.Storage/storageAccounts"

If you want to append a tag to the existing tags on a specific resource, you can use the below Azure CLI script to do this

az resource update --set tags.'Department'='ITS' -g newresgroup -n DemoStorage --resource-type "Microsoft.Storage/storageAccounts"

If you want to overwrite the existing tags on a particular resource group, you can use the below Azure CLI script.

az group update -n newresgroup --tags 'TSinfo=HR' 'Technology=Android'

You can use the below Azure CLI script to append a tag to the existing tags for a resource group.

az group update -n newresgroup --set tags.'Category'='Info'

If you want to retrieve the tags for a particular resource, you can use the below Azure CLI script.

az resource show -n DemoStorage -g newresgroup --resource-type "Microsoft.Storage/storageAccounts" --query tags

If you want to retrieve the existing tags for a specific resource group, you can use the below Azure CLI scripts.

az group show -n newresgroup --query tags

You can use the below Azure CLI script to get all the resources that have a particular name and value

az resource list --tag Technology=Android

This is all about Azure Tags Azure CLI. As explained above, you can use the above Azure CLI scripts for different purposes.

Azure Tag Policy

Azure tag Policy is a BuiltIn policy defined in Azure Portal that helps us to automate the tagging process. In simple words, instead of adding the tags to the resources manually, it will help us to create and apply the tags while the creation time of the resource. During the deployment of the resources, it will apply the tags based on the Organization rule how it defined.

There are different BuiltIn policy defined in Azure Portal, Thease are as below

Add tag to resource groups

You will find this BuiltIn policy defined in the Azure Portal that Adds the tag and value when any resource group missing this tag is created or updated.

You can find this Policy in the below path in the Azure Portal

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2F726aca4c-86e9-4b04-b0c5-073027359532
Azure Tag Policy

Add the tag to resources

This BuiltIn Policy Adds the provided tag and value when any of the resource missing this tag is created or updated.

You can find this Policy in the below path in the Azure Portal

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2F4f9dc7db-30c1-420c-b61a-e1d640128d26
azure policy samples

Add or replace the tag on resource groups

This can Add or replace the provided tag and value when any resource group is created or updated

You can check the below path for the BuiltIn policy in the Azure Portal

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2Fd157c373-a6c4-483d-aaad-570756956268
azure tag policy examples

Add or replace a tag on resources

This policy will help you to add or replace the provided tag and value when any resource is created or updated.

You can find this policy in the Azure Portal in the below path

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2F5ffd78d9-436d-4b41-a421-5baa819e3008
azure tag policy examples

Append the tag and its value from a resource group

This Azure tag Builtin policy helps to append the provided tag with its value from the resource group when any of the resources that are missing this tag is created or updated.

Find the built in policy in the Azure portal in the below path

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2F9ea02ca2-71db-412d-8b00-7c7ca9fcd32d
azure tag policy definition

Append the tag and its value to the resource groups

This Azure builtin tag helps you to Append the provided tag and value when any resource group that is missing, this tag is created or updated.

Below is the path for the builtin policy in Azure portal.

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2F49c88fc8-6fd1-46fd-a676-f12d1d3a4c71
Append a tag and its value to resource groups

Append Azure tag and its value to resources

This builtin tag helps to append the provided tag and value when any resource that is missing this tag is created or updated.

Find the built in policy in the Azure portal in the below path

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2F2a0e14a6-b0a6-4fab-991a-187a4f81c498
Append a tag and its value to resources

Inherit the tag from the resource group

When a resource is created or updated, this Azure tag policy helps you to add or replace the provided tag and value from the parent resource group.

You can find this builtin policy in the below path in the Azure Portal

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2Fcd3aa116-8754-49c9-a813-ad46512ece54
Inherit a tag from the resource group

Inherit the tag from a resource group if missing

This inbuilt Azure tag policy helps to add the provided tag with its value from the parent resource group when any of the resources missing this tag is created or updated.

You can see the below path in the Azure Portal to find the definition of this Azure tag Policy

https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2Fea3f2387-9b95-492a-a190-fcdc54f7b070
Inherit a tag from the resource group if missing

For more details, you can refer to the below Microsoft Official site

https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/tag-policies

Azure Tagging Best Practices

The Azure tagging can be done simply using the Azure Portal, PowerShell, Azure CLI, etc. Let’s discuss here, few points on Azure Tagging Best Practices.

  • For an Azure tag name, the maximum number of characters allowed is 512. But to name an Azure tag for a storage account is maximum allowed character is 128 characters.
  • There are some reserved keywords like “Azure”, “Windows”, “Microsoft” and you cannot use these keywords as the prefix for your Azure tags.
  • You can associate a maximum of 15 tags to each resource.
  • Inheritance property is not supported by Azure Tags.
  • If you have a requirement to assign multiple values to a particular tag name, then you can do that using the JSON strings with the ARM template.
  • It is suggested to automate the tagging process with the help of PowerShell, Azure CLI, etc.
  • It’s always better to create the tag for the resource early meaning create the tag for the resource while you are creating the resource.
  • Always give a meaningful name to the Azure tag like environment, version, etc which helps to understand the category of the resources easily.
  • Follow the Azure policies and use a standard naming convention while naming the Azure tag.

So as part of Azure Tagging Best Practices, these are few best practices, which you need to keep in mind while deciding the Azure tag name.

You may also like following the below Articles:

Conclusion

Well, here in this article, we discussed, How Do I Make Azure Tag, What Is A Tag In Azure?, Why Use The Azure tag? and we also discussed, Azure Tags PowerShell and Azure Tags Azure CLI, Azure Tag Policy, and finally, we discussed Azure Tagging Best Practices. Hope you enjoyed this tutorial !!!

Leave a Comment