Gallery › Tags › Azure built-in policies
Append a tag and its value to resources
Converted Policy Append Mode Indexed Version 1.0.1
Appends the specified tag and value when any resource which is missing this tag is created or updated. Does not modify the tags of resources created before this policy was applied until those resources are changed. Does not apply to resource groups. New 'modify' effect policies are available that support remediation of tags on existing resources (see https://aka.ms/modifydoc).
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONApplyTag_Append.json · 49 lines
{
"properties": {
"displayName": "Append a tag and its value to resources",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Appends the specified tag and value when any resource which is missing this tag is created or updated. Does not modify the tags of resources created before this policy was applied until those resources are changed. Does not apply to resource groups. New 'modify' effect policies are available that support remediation of tags on existing resources (see https://aka.ms/modifydoc).",
"metadata": {
"version": "1.0.1",
"category": "Tags"
},
"version": "1.0.1",
"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": {
"field": "[concat('tags[', parameters('tagName'), ']')]",
"exists": "false"
},
"then": {
"effect": "append",
"details": [
{
"field": "[concat('tags[', parameters('tagName'), ']')]",
"value": "[parameters('tagValue')]"
}
]
}
},
"versions": [
"1.0.1"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/2a0e14a6-b0a6-4fab-991a-187a4f81c498",
"name": "2a0e14a6-b0a6-4fab-991a-187a4f81c498"
}Bylaw2a0e14a6-b0a6-4fab-991a-187a4f81c498.bylaw.ps1 · 34 lines
# Converted from ApplyTag_Append.json by ConvertTo-Bylaw.
Policy '2a0e14a6-b0a6-4fab-991a-187a4f81c498' {
Properties @{
DisplayName = 'Append a tag and its value to resources'
Description = 'Appends the specified tag and value when any resource which is missing this tag is created or updated. Does not modify the tags of resources created before this policy was applied until those resources are changed. Does not apply to resource groups. New ''modify'' effect policies are available that support remediation of tags on existing resources (see https://aka.ms/modifydoc).'
Version = '1.0.1'
Category = 'Tags'
PolicyVersion = '1.0.1'
Mode = 'Indexed'
}
Parameter TagName @{
Type = 'String'
DisplayName = 'Tag Name'
Description = 'Name of the tag, such as ''environment'''
}
Parameter TagValue @{
Type = 'String'
DisplayName = 'Tag Value'
Description = 'Value of the tag, such as ''production'''
}
Resource * {
Require 'tag (Param TagName) exists' {
Tag (Param TagName) | Must -Exist
}
}
Append {
Tag (Param TagName) | Add (Param TagValue)
}
}Source: built-in-policies/policyDefinitions/Tags/ApplyTag_Append.json in Azure/azure-policy, under the MIT licence.
Bylaw