• Rohit Anand

Azure Policy: Apply Multiple Tags to Resource Group with Append Action

We recently were working on the tagging policy to logically organize them into a taxonomy. We started organizing the resource group and later we planned to inherit the tags to resources. It was quite an amazing experience and the best thing that tags gives you the flexibility to work with cost accounting.

Let's talk about Azure Policy!!

Azure Policy is a service in Azure that you use to create, assign, and manage policies. These policies enforce different rules and effects over your resources, so those resources stay compliant with your corporate standards and service level agreements. Azure Policy meets this need by evaluating your resources for non-compliance with assigned policies. All data stored by Azure Policy is encrypted at rest.

Let’s understand Azure Tag Policy Deployment and assume if your customer says that they wanted the below tags which will be going to help to logically organize the resources in Azure.

Tags are:




BusinessUnit: Purpose:

You can apply as many tags based on the needs and understanding within your IT teammates. Azure offers quick built-in templates to deploy Azure Tags Policy but it doesn’t suit in every condition where you wanted to keep your custom values based on needs.

I have written up the JSON template to help you with deploying the tag policy to the resource group using the append effect.

Here’s the link of my GitHub repo:

{ "mode": "All", "policyRule": { "if": { "allOf": [ { "exists": "false", "field": "[concat('tags[', parameters('tagName1'), ']')]" }, { "field": "type", "equals": "Microsoft.Resources/subscriptions/resourceGroups" } ] }, "then": { "effect": "append", "details": [ { "field": "[concat('tags[', parameters('tagName1'), ']')]", "value": "[parameters('tagValue1')]" }, { "field": "[concat('tags[', parameters('tagName2'), ']')]", "value": "[parameters('tagValue2')]" }, { "field": "[concat('tags[', parameters('tagName3'), ']')]", "value": "[parameters('tagValue3')]" }, { "field": "[concat('tags[', parameters('tagName4'), ']')]", "value": "[parameters('tagValue4')]" }, { "field": "[concat('tags[', parameters('tagName5'), ']')]", "value": "[parameters('tagValue5')]" } ] } }, "parameters": { "tagName1": { "type": "String", "metadata": { "displayName": "Tag Name1", "description": "Owner" }, "defaultValue": "Owner" }, "tagValue1": { "type": "String", "metadata": { "displayName": "Tag Value1", "description": "Person responsible for this resource" }, "defaultValue": "username@turtledesk.com" }, "tagName2": { "type": "String", "metadata": { "displayName": "Tag Name2", "description": "EstimatedMonthlyCost" }, "defaultValue": "EstimatedMonthlyCost" }, "tagValue2": { "type": "String", "metadata": { "displayName": "Tag Value2", "description": "Estimated Monthly Cost of the resources inside Resource Group" }, "defaultValue": "$000.0" }, "tagName3": { "type": "String", "metadata": { "displayName": "Tag Name3", "description": "ReviewDate" }, "defaultValue": "ReviewDate" }, "tagValue3": { "type": "String", "metadata": { "displayName": "Tag Value3", "description": "Expected Review Date for the resource" }, "defaultValue": "mm/dd/yyyy" }, "tagName4": { "type": "String", "metadata": { "displayName": "Tag Name4", "description": "BusinessUnit" }, "defaultValue": "BusinessUnit" }, "tagValue4": { "type": "String", "metadata": { "displayName": "Tag Value4", "description": "BusinessUnit to which resource group belong to" }, "allowedValues": [ "Practices", "Delivery", "Corp", "IT" ], "defaultValue": "IT" }, "tagName5": { "type": "String", "metadata": { "displayName": "Tag Name5", "description": "Purpose of the resource group" }, "defaultValue": "Purpose" }, "tagValue5": { "type": "String", "metadata": { "displayName": "Tag Value5", "description": "Purpose of the resource group" }, "allowedValues": [ "Production", "Demo", "ClientProject", "Development/Sandbox", "Training/Learning" ], "defaultValue": "Demo" } } }

Hope you will like the blog post and will do add soon the interesting blog post about Tag policy. Happy Learning.

40 views0 comments