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?
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.
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.
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With