Automatic resource tagging with Azure Policy

In Azure we can link tags onto different resources, resource groups and subscriptions. We can use resource tagging for various reasons. With Azure Policy we can automate this process even further, linking different resources automatically based on what we want to achieve. For example, giving every resource in a specific resource group a tag."

For some inspiration on to how to actually use Azure Tags, check out my earlier blog: https://justinverstijnen.nl/10-ways-to-use-tags-in-microsoft-azure/


The solution described

The solution we are going to build in this post, is simply a Azure Policy which we will link to a specific resource group in Azure. This simply looks like this:

In this Azure Policy, we will define that we want resource groups and underlying resources a specific tag based on certain conditions. Conditions like:

  • Resource group
  • Production or Testing environment
  • Region of the resource

Step 1: Create the Azure Policy definition

We can now create our Azure Policy that alters the resources and adds a tag just like we want to.

Open the Azure Portal and go to “Policy”. We will land on the Policy compliancy dashboard:

jv-media-5017-70eb6b5c15f1.png

As for this purpose, Microsoft has already two templates ready which we can use. You can also choose to start from scratch. There are many more policy templates available from here, but they all need to be implemented the same as this guide.

https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/tag-policies

I selected the “Add a tag to resources” policy template. Now we can select a scope, from where the policy must apply. We can also give it a custon name and description and possible exclusions.

jv-media-5017-fef734887c07.png

Click “Next”.

On the “Parameters” tab, fill in the tag name (1st) and tag value (2nd) part of the tag to assign:

jv-media-5017-a33279b2ff66.png

For example, my testing resource group:

jv-media-5017-bc29218b800c.png

Click “Next” and you reach the “Remediation” tab.

jv-media-5017-ff1a4e8bf80b.png

The remediation task is the actual task that applies the tags. The definition is only stating what you want, the remediation task is the executor.

Enable the checkbox and select the policy you just selected.

jv-media-5017-e28b03c5ac1a.png

On the “Managed Identity” tab, select to use a System assigned managed identity and finish the wizard.

jv-media-5017-059dde37ebb3.png


Step 2: Create a dummy resource

Now I created a dummy resource, just to check if it gets a tags assigned and test our current configuration. I created a public IP address as this is a easy and cheap resource which is deployed instantly.

jv-media-5017-252c314b6547.png

jv-media-5017-8df378386419.png

Now we have to wait for some time, as the remediation task can take up to an hour to actually add the tag. In my case, it took a few minutes.


Step 3: Let’s test the results

In the Policy, the remediation task is now showing as running:

jv-media-5017-f5e84325e50b.png

Now I will go back to the Public IP address and check the results:

jv-media-5017-2cbd795d7a95.png

It indeed got the tag assigned automatically after about 5 minutes. This is really cool.


Summary

Assigning tags automatically with Azure Policy is a great way to automate the process. It ensures every resource is tagged and no manual intervention is needed where a person can forget to link things or make a minor mistake.

Thank you for reading this blog and I hope it was helpful.

Sources

These sources helped me by writing and research for this post;

  1. https://justinverstijnen.nl/10-ways-to-use-tags-in-microsoft-azure/
  2. https://justinverstijnen.nl/deploy-resource-group-locks-automatically-with-azure-policy/
  3. https://justinverstijnen.nl/automatic-azure-boot-diagnostics-monitoring-with-azure-policy/

 

End of the page 🎉

You have reached the end of the page. You can navigate through other blog posts as well, share this post on X, LinkedIn and Reddit or return to the blog posts collection page. Thank you for visiting this post.

Go back to Blog homepage

If you find this page and blog very useful and you want to leave a donation, you can use the button below to buy me a beer. Hosting and maintaining a website takes a lot of time and money. Thank you in advance and cheers :)

Buy me a beer

The terms and conditions apply to this post.

Report an issue with this page

Last modified August 19, 2026: Updated release date (ea4a74d)