-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Description
Describe the bug
When using az resource tag, any existing tags on the object are overwritten. There is no mention of this in the documentation, and to my mind, is unexpected behavior.
To Reproduce
Create a resource in the UI (or via cli) and ensure it has some tag on it.
Using the cli, add a tag. Eg. az resource tag --tags environment=production --ids /subscriptions/.........
Now verify that the resource has the newly added tag, but is missing the initially set tag.
For example,
=> az resource show --ids /subscriptions/......../adrian-test
{
"id": "/subscriptions/......../adrian-test",
"name": "adrian-test",
"tags": {
"testing": "1234"
},
"type": "Microsoft.Compute/virtualMachines"
}
=> az resource tag --tags environment=devops owner=maverick project=infrastructure --ids /subscriptions/......../adrian-test
{
"id": "/subscriptions/......../adrian-test",
"name": "adrian-test",
"tags": {
"environment": "devops",
"owner": "maverick",
"project": "infrastructure",
},
"type": "Microsoft.Compute/virtualMachines"
}
=> az resource show --ids /subscriptions/......../adrian-test
{
"id": "/subscriptions/......../adrian-test",
"name": "adrian-test",
"tags": {
"environment": "devops",
"owner": "maverick",
"project": "infrastructure",
},
"type": "Microsoft.Compute/virtualMachines"
}
Expected behavior
Either the documentation needs to be adjusted to explain this behavior, or ideally the behavior would be additive. Specifically, tags should only be cleared when explicitly set to "" (per the documentation, "Use "" to clear existing tags."). Otherwise, any changes should be additive.
Environment summary
az --version
azure-cli 2.2.0
command-modules-nspkg 2.0.3
core 2.2.0
nspkg 3.0.4
telemetry 1.0.4
Extensions:
azure-devops 0.17.0
Python location '/usr/local/Cellar/azure-cli/2.2.0_1/libexec/bin/python'
Extensions directory '/Users/kostrubi/.azure/cliextensions'
Python (Darwin) 3.8.2 (default, Mar 11 2020, 00:29:50)
[Clang 11.0.0 (clang-1100.0.33.17)]
Legal docs and information: aka.ms/AzureCliLegal
Your CLI is up-to-date.