How to tag a Linux virtual machine in Azure

This article describes different ways to tag a Linux virtual machine in Azure through the Resource Manager deployment model. Tags are user-defined key/value pairs which can be placed directly on a resource or a resource group. Azure currently supports up to 15 tags per resource and resource group. Tags may be placed on a resource at the time of creation or added to an existing resource. Please note, tags are supported for resources created via the Resource Manager deployment model only.

Tagging a Virtual Machine through Templates

First, let’s look at tagging through templates. This template places tags on the following resources: Compute (Virtual Machine), Storage (Storage Account), and Network (Public IP Address, Virtual Network, and Network Interface). This template is for a Windows VM but can be adapted for Linux VMs.

Click the Deploy to Azure button from the template link. This will navigate to the Azure portal where you can deploy this template.

Simple deployment with Tags

This template includes the following tags: Department, Application, and Created By. You can add/edit these tags directly in the template if you would like different tag names.

Azure tags in a template

As you can see, the tags are defined as key/value pairs, separated by a colon (:). The tags must be defined in this format:

    “tags”: {
        “Key1” : ”Value1”,
        “Key2” : “Value2”
    }

Save the template file after you finish editing it with the tags of your choice.

Next, in the Edit Parameters section, you can fill out the values for your tags.

Edit Tags in Azure portal

Click Create to deploy this template with your tag values.

Tagging through the Portal

After creating your resources with tags, you can view, add, and delete tags in the portal.

Select the tags icon to view your tags:

Tags icon in Azure portal

Add a new tag through the portal by defining your own Key/Value pair, and save it.

Add new Tag in Azure portal

Your new tag should now appear in the list of tags for your resource.

New Tag saved in Azure portal

Tagging with Azure CLI

To begin, you need the latest Azure CLI 2.0 installed and logged in to an Azure account using az login.

You can view all properties for a given Virtual Machine, including the tags, using this command:

az vm show --resource-group MyResourceGroup --name MyTestVM

To add a new VM tag through the Azure CLI, you can use the azure vm update command along with the tag parameter --set:

az vm update \
    --resource-group MyResourceGroup \
    --name MyTestVM \
    --set tags.myNewTagName1=myNewTagValue1 tags.myNewTagName2=myNewTagValue2

To remove tags, you can use the --remove parameter in the azure vm update command.

az vm update --resource-group MyResourceGroup --name MyTestVM --remove tags.myNewTagName1

Now that we have applied tags to our resources Azure CLI and the Portal, let’s take a look at the usage details to see the tags in the billing portal.

Viewing your tags in the usage details

Tags placed on Compute, Network, and Storage resources in the Resource Manager deployment model will be populated in your usage details in the billing portal.

Click on Download usage details to view the usage details in your subscription.

Usage details in Azure portal

Select your billing statement and the Version 2 usage details:

Version 2 Preview Usage Details in Azure portal

From the usage details, you can see all of the tags in the Tags column:

Tags column in Azure portal

By analyzing these tags along with usage, organizations will be able to gain new insights into their consumption data.

Next steps