How to set or change tags on an existing keyvault object with az cli command

Phillip van Ee 1 Reputation point
2021-12-05T22:59:00.63+00:00

It seems you can only set/add them during creation
If you use az keyvault create on an existing keyvault, you get a message that it already exists (no update possibility with this command?)
Using az keyvault update it just fails, either [a] with error or [b] without an error and just showing all propsties (like a show subcommand)

Tried many combinations and failed, it really doesn't work the same with other azure objects.

Tried both bash and Powershell,a s they can differ in the way hwo to quote things.

Google and the microsoft websites revealed nothing.

Manually editing via the portal is simple and the same as with other objects.

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,194 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Siva-kumar-selvaraj 15,606 Reputation points
    2021-12-06T07:17:42.71+00:00

    Hello @Phillip van Ee ,

    Thanks for reaching out.

    You can only add tags during the Key Vault creation process using Azure CLI (BASH) cmdlets but alternatively you can use Azure PowerShell or Key Vault REST API to update Tags even after vault creations, as illustrated below:

    PowerShell:
    update-AzKeyVault -Name -ResourceGroupName -Tag @{ 'Severity' = 'high'; 'IT' = "true" }

    (or)

    $Tags = @{ 'Severity' = 'high'; 'cxp' = "true" } Note: This cmdlet adds a parameter in the type of System.Collections.Hashtable
    update-AzKeyVault -Name {VaultName} -ResourceGroupName {RGname} -Tag $Tags

    Outcome:
    155211-image.png

    REST API using HTTP REQUEST :

    HTTP Method:
    PUT

    Absolute Uri:
    https://management.azure.com/subscriptions/{Subscription-ID}/resourceGroups/{RGname}/providers/Microsoft.KeyVault/vaults/{VaultName}?api-version=2019-09-01

    Headers:
    x-ms-client-request-id : 68535a96-62c0-4ce1-85d5-2af17b3102da
    accept-language : en-US

    Example Body:
    {
    "location": "East US",
    "tags": {
    "IT": "true",
    "Severity": "high"
    },

    Example: https://learn.microsoft.com/en-us/powershell/module/az.keyvault/update-azkeyvault?view=azps-6.6.0#example-3--set-tags

    Hope this was helpful.

    ------
    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

    0 comments No comments

  2. Rodrigo Marques Teixeira 0 Reputation points
    2024-02-15T19:18:11.1266667+00:00

    We can set Tags, now, for Secrets in Keyvault using the Azure Portal.

    0 comments No comments