Need a way to change every tag with a given value to another across subscriptions

Jonathan Garcia 1 Reputation point
2022-02-25T17:38:48.03+00:00

For example, if I have "CostCenter" tag with value "XYZ", how would I change all of the resources/resource groups with "XYZ" to "ABC"?

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
1,018 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 18,996 Reputation points Moderator
    2022-02-25T17:47:30.377+00:00

    @Jonathan Garcia Welcome to Microsoft Q & A Community Forum. You can use Azure Policy to modify your tags. Here is a sample policy for your reference.

    {  
        "properties": {  
            "displayName": "Add or replace a tag on resource groups",  
            "mode": "All",  
            "description": "Adds or replaces the specified tag and value when any resource group is created or updated. Existing resource groups can be remediated by triggering a remediation task.",  
            "metadata": {  
                "category": "Tags"  
            },  
            "parameters": {  
                "tagName": {  
                    "type": "String",  
                    "metadata": {  
                        "displayName": "Tag Name",  
                        "description": "Name of the tag, such as 'environment'"  
                    }  
                },  
                "tagValue": {  
                    "type": "String",  
                    "metadata": {  
                        "displayName": "Tag Value",  
                        "description": "Value of the tag, such as 'production'"  
                    }  
                }  
            },  
            "policyRule": {  
                "if": {  
                    "allOf": [{  
                            "field": "type",  
                            "equals": "Microsoft.Resources/subscriptions/resourceGroups"  
                        },  
                        {  
                            "field": "[concat('tags[', parameters('tagName'), ']')]",  
                            "notEquals": "[parameters('tagValue')]"  
                        }  
                    ]  
                },  
                "then": {  
                    "effect": "modify",  
                    "details": {  
                        "roleDefinitionIds": [  
                            "/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"  
                        ],  
                        "operations": [{  
                            "operation": "addOrReplace",  
                            "field": "[concat('tags[', parameters('tagName'), ']')]",  
                            "value": "[parameters('tagValue')]"  
                        }]  
                    }  
                }  
            }  
        }  
    }  
    

    References :


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.