You are currently viewing Azure Policy Treasure Collection

Azure Policy Treasure Collection

Today I decided to start creating a small repository with all useful custom policies I created by myself or I found during huge researches. This article is more a wiki than a blog post and will be always updated if new things come up.

The great thing here is that you can just copy paste the Azure policy snippets and reuse it.

Table of content

Adding a creation tag on Resources and Resource Groups

  • This policy is used to add automatically the Creation Date to Azure Resources and Resource Groups during the Creation or Deployment.
  • Tag Name = DateCreated
  • Tag Value = current UTC timestamp in the following format: 2021-02-15T13:43:28.8652865Z
    –> If somebody knows how to trim or format this please let me know 🙂
{
  "mode": "All",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "tags['DateCreated']",
          "exists": "false"
        }
      ]
    },
    "then": {
      "effect": "append",
      "details": [
        {
          "field": "tags['DateCreated']",
          "value": "[utcNow()]"
        }
      ]
    }
  },
  "parameters": {}
}

This Post Has One Comment

  1. Woojin

    Hi, I am trying to add hours to the utcNow() function but can’t think of a way to do it as the function outputs a String instead of a DateTime. In terms of trimming the output, you can use the substring(utcNow(), n, m) to trim it.

Leave a Reply