Search code examples
azureazure-cli

How to assign a new tag on existing SQL Server using Azure CLI?


In docs for Azure CLI I can see how to create a tag on my resource. It works as supposed to. However, it's clunky to specify the ID, so I wonder if there's a way to add tag to a resource only knowing its name.

Naturally, I could do the following.

$SqlServerId = az sql server show `
                 --resource-group ressy-grouppie `
                 --name sql-servy-v12 `
                 --query "id"
az tag create --resource-id $SqlServerId --tags monkey=donkey

But I can't help if there's a shorter way, without actually creating the intermediate value holding the ID. It seems like the general philosophy of the Azure CLI is to refer to things by their names not only IDs.


Solution

  • It seems like the general philosophy of the Azure CLI is to refer to things by their names not only IDs.

    Unfortunately, You cannot create a tag on a resource in Azure Services by just using its name, The functionality of creating a tag command requires the resource id of the resource and not just the name.

    Resource id for Sql server is :

    /subscriptions/xxx/resourceGroups/yyy/providers/Microsoft.Sql/servers/zzz
    

    Here xxx is subscription id yyy is name of the resource group zzz is name of the server

    So id not so different.

    And currently as of today, the only way of doing this is the way you have done:

    enter image description here

    enter image description here