last sync: 2021-Nov-26 17:15:01 UTC

Azure Policy definition

Add or replace a tag on subscriptions

Name Add or replace a tag on subscriptions
Azure Portal
Id 61a4d60b-7326-440e-8051-9f94394d4dd1
Version 1.0.0
details on versioning
Category Tags
Microsoft docs
Description Adds or replaces the specified tag and value on subscriptions via a remediation task. Existing resource groups can be remediated by triggering a remediation task. See https://aka.ms/azurepolicyremediation for more information on policy remediation.
Mode All
Type BuiltIn
Preview FALSE
Deprecated FALSE
Effect Fixed: modify
Used RBAC Role
Role Name Role Id
Tag Contributor 4a9ae827-6dc8-4573-8ac7-8239d42aa03f
History
Date/Time (UTC ymd) (i) Change type Change detail
2020-11-17 14:39:37 add 61a4d60b-7326-440e-8051-9f94394d4dd1
Used in Initiatives none
JSON
{
  "displayName": "Add or replace a tag on subscriptions",
  "policyType": "BuiltIn",
  "mode": "All",
  "description": "Adds or replaces the specified tag and value on subscriptions via a remediation task. Existing resource groups can be remediated by triggering a remediation task. See https://aka.ms/azurepolicyremediation for more information on policy remediation.",
  "metadata": {
    "version": "1.0.0",
    "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"
        },
        {
          "field": "[concat('tags[', parameters('tagName'), ']')]",
          "notEquals": "[parameters('tagValue')]"
        }
      ]
    },
    "then": {
      "effect": "modify",
      "details": {
        "roleDefinitionIds": [
          "/providers/microsoft.authorization/roleDefinitions/4a9ae827-6dc8-4573-8ac7-8239d42aa03f"
        ],
        "operations": [
          {
            "operation": "addOrReplace",
            "field": "[concat('tags[', parameters('tagName'), ']')]",
            "value": "[parameters('tagValue')]"
          }
        ]
      }
    }
  }
}