Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning multiple tags to a resource via Azure CLI results in one big tag when using a variable

When creating VM via az cli (bash) with a list of tags.

First set this variable:
tags='env=qa servertype=frontend Distinct=qa-frontend25 CI=Yes DataDog:True'

However when running the below command in bash

az vm create ... --tags "${tags}"

It creates one long tag that has key env and value qa servertype=frontend Distinct=qa-frontend25 CI=Yes DataDog=True

From Azure CLI documentation

--tags
     Space-separated tags in 'key[=value]' format. 

What am missing here?

like image 867
J00MZ Avatar asked Dec 11 '18 12:12

J00MZ


People also ask

Can you add multiple tags to the same Azure resource?

You can also add multiple tags to single Azure Resource. Also, you can untag the multiple resources in a single step as we did for tagging. Once resources are tagged with the name, you can get all the resources for that specific tag name.

Which CLI command is used to specify values for existing tags?

az tag create. Create tags on a specific resource. The az tag create command with an id creates or updates the entire set of tags on a resource, resource group or subscription.

When applying a tag to an Azure resource What two things do you need to supply?

Azure PowerShell offers two commands to apply tags: New-AzTag and Update-AzTag. You need to have the Az. Resources module 1.12. 0 version or later.

Can Azure tag have multiple values?

A predefined Azure tag can have multiple values, but when you apply the tag to a resource or resource group, you apply the tag name and only one of its values. For example, you can create a predefined Department tag with a value for each department, such as Finance, Human Resources, and IT.


1 Answers

If you want to create multi-tag to one VM, you should add the parameter --tags like this:

--tags 'tag1=test1' 'tag2=test2'

The result like this:

enter image description here

It also shows in the document az vm create that you provide. There is a misunderstanding with you.

--tags Space-separated tags in 'key[=value]' format. Use "" to clear existing tags.

Update

Yeah, you can set multi-tag in a variable and take it in the command like this:

tags="tag1=test1 tag2=test2"

az vm create -g resourceGroupName -n vmName --image image --tags $tags

It will work well and answer for @Johan, if you remove quotes it also works. It's a great question. Actually, the variable works in the CLI command like this:

--tags $tags -> --tags tag1=test1 tag2=test2

Just like using echo $tags in the bash.

like image 132
Charles Xu Avatar answered Sep 28 '22 07:09

Charles Xu