Use tags to organize your Azure resources (with the Azure CLI)!

%3CLINGO-SUB%20id%3D%22lingo-sub-1798955%22%20slang%3D%22en-US%22%3EUse%20tags%20to%20organize%20your%20Azure%20resources%20(with%20the%20Azure%20CLI)!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1798955%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Azure%20friends%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EStart%20the%20CloudShell%20in%20the%20Azure%20portal%26nbsp%3Bor%20go%20to%20the%20following%20URL%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fshell.azure.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fshell.azure.com%2F%3C%2FA%3E%3C%2FP%3E%3CP%3EPlease%20start%20with%20the%20following%20steps%20to%20begin%20the%20deployment%20(the%20Hashtags%20are%20comments)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23Here%20you%20can%20find%20out%20which%20subscription%20you%20are%20working%20with%3CBR%20%2F%3E%3CSTRONG%3Eaz%20account%20show%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23View%20all%20subscriptions%3CBR%20%2F%3E%3CSTRONG%3Eaz%20account%20list%20--all%20--output%20table%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23change%20the%20subscription%20(if%20necessary)%3CBR%20%2F%3E%3CSTRONG%3Eaz%20account%20set%20--subscription%20%22Name%20of%20the%20Subscription%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20To%20overwrite%20the%20tags%20on%20a%20resource%3CBR%20%2F%3E%3CSTRONG%3Eaz%20resource%20tag%20--tags%20'Dept%3DIT'%20'Environment%3DTest'%20-g%20tw-rg01%20-n%20vnet-base%20--resource-type%20%22Microsoft.Network%2FvirtualNetworks%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20To%20append%20a%20tag%20to%20the%20existing%20tags%20on%20a%20resource%3CBR%20%2F%3E%3CSTRONG%3Eaz%20resource%20update%20--set%20tags.'Status'%3D'Approved'%20-g%20tw-rg01%20-n%20vnet-base%20--resource-type%20%22Microsoft.Network%2FvirtualNetworks%22%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20To%20overwrite%20the%20existing%20tags%20on%20a%20resource%20group%3CBR%20%2F%3E%3CSTRONG%3Eaz%20group%20update%20-n%20tw-rg01%20--tags%20'Environment%3DTest'%20'Dept%3DIT'%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20To%20append%20a%20tag%20to%20the%20existing%20tags%20on%20a%20resource%20group%3CBR%20%2F%3E%3CSTRONG%3Eaz%20group%20update%20-n%20tw-rg01%20--set%20tags.'Status'%3D'Approved'%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20To%20see%20the%20existing%20tags%20for%20a%20resource%3CBR%20%2F%3E%3CSTRONG%3Eaz%20resource%20show%20-n%20vnet-base%20-g%20tw-rg01%20--resource-type%20%22Microsoft.Network%2FvirtualNetworks%22%20--query%20tags%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20To%20see%20the%20existing%20tags%20for%20a%20resource%20group%3CBR%20%2F%3E%3CSTRONG%3Eaz%20group%20show%20-n%20tw-rg01%20--query%20tags%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20To%20get%20all%20the%20resources%20that%20have%20a%20particular%20tag%20and%20value%3CBR%20%2F%3E%3CSTRONG%3Eaz%20resource%20list%20--tag%20Dept%3DFinance%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23%20To%20get%20resource%20groups%20that%20have%20a%20specific%20tag%3CBR%20%2F%3E%3CSTRONG%3Eaz%20group%20list%20--tag%20Dept%3DIT%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENow%20you%20have%20organized%20Azure%20Tags%20with%20the%20Azure%20CLI!%20Congratulations!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20hope%20this%20article%20was%20useful.%20Best%20regards%2C%20Tom%20Wechsler%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EP.S.%26nbsp%3BAll%20scripts%20(%23PowerShell%2C%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F73893%22%20target%3D%22_blank%22%3E%40azure%3C%2FA%3E%20CLI%2C%20%23Terraform%2C%20%23ARM)%20that%20I%20use%20can%20be%20found%20on%20github!%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Ftomwechsler%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Ftomwechsler%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1798955%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Resource%20Management%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
MVP

 

Hi Azure friends,

 

Start the CloudShell in the Azure portal or go to the following URL: https://shell.azure.com/

Please start with the following steps to begin the deployment (the Hashtags are comments):

 

#Here you can find out which subscription you are working with
az account show

 

#View all subscriptions
az account list --all --output table

 

#change the subscription (if necessary)
az account set --subscription "Name of the Subscription"

 

# To overwrite the tags on a resource
az resource tag --tags 'Dept=IT' 'Environment=Test' -g tw-rg01 -n vnet-base --resource-type "Microsoft.Network/virtualNetworks"

 

# To append a tag to the existing tags on a resource
az resource update --set tags.'Status'='Approved' -g tw-rg01 -n vnet-base --resource-type "Microsoft.Network/virtualNetworks"

 

# To overwrite the existing tags on a resource group
az group update -n tw-rg01 --tags 'Environment=Test' 'Dept=IT'

 

# To append a tag to the existing tags on a resource group
az group update -n tw-rg01 --set tags.'Status'='Approved'

 

# To see the existing tags for a resource
az resource show -n vnet-base -g tw-rg01 --resource-type "Microsoft.Network/virtualNetworks" --query tags

 

# To see the existing tags for a resource group
az group show -n tw-rg01 --query tags

 

# To get all the resources that have a particular tag and value
az resource list --tag Dept=Finance

 

# To get resource groups that have a specific tag
az group list --tag Dept=IT

 

Now you have organized Azure Tags with the Azure CLI! Congratulations!

 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, @azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler

0 Replies