2
votes

Is it possible to update tags of existing resource group, using Azure Resource Manager template? Cause, each time i do a deployment to Azure via Azure Resource Manager - my tags on Azure Resource Group are being removed :(

1
How are you doing the deployment? PowerShell?BenV

1 Answers

6
votes

I think the PowerShell implementation of tags on resources and groups is not implemented the way you would expect, which makes this a challenge at the moment. I don't know of a way append a tag without some gymnastics in deconstructing the hashtable.

Whenever you set tags in PowerShell it's a "replace" and not an append. So you could get, then append to the hashtable and put it back but I haven't found a good way to do that. See https://github.com/Azure/azure-powershell/issues/726

If you just want to replace tags on a resource group, rather than using New-AzureResourceGroup (I'm assuming that's what you're using due to the behavior I'm seeing) use:

    Set-AzureResourceGroup -Name GroupName -Tag @{Name='TagName';Value='TagValue'} #this will replace all the tags with this one
    New-AzureResourceGroupDeployment -ResourceGroupName GroupName ...

When you use New-AzureResourceGroup, if you want to update tags you'd have to create a hash table with the existing and new tags.