@Prarthan Jain (L&T INFOTECH LIMITED) Welcome to Microsoft Q & A Community Forum. Here is a sample policy for your reference. This policy checks whether tags which are part of arrays exists or not. If it does not exist, it automatically adds the tag name and tag value to the resource. If the tag exists but value is not expected, it shows as non-compliant and you can remediate by creating remediation task.
{
"mode": "All",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"in": [
"Microsoft.Compute/virtualMachines",
"Microsoft.Storage/storageAccounts",
"Microsoft.Network/networkInterfaces"
]
},
{
"anyOf": [
{
"not": {
"field": "[concat('tags[', parameters('tags')[0].tagName, ']')]",
"exists": "true"
}
},
{
"not": {
"field": "[concat('tags[', parameters('tags')[1].tagName, ']')]",
"exists": "true"
}
}
]
}
]
},
"then": {
"effect": "modify",
"details": {
"roleDefinitionIds": [
"/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"operations": [
{
"operation": "addOrReplace",
"field": "[concat('tags[', parameters('tags')[0].tagName, ']')]",
"value": "[parameters('tags')[0].tagValue]"
},
{
"operation": "addOrReplace",
"field": "[concat('tags[', parameters('tags')[1].tagName, ']')]",
"value": "[parameters('tags')[1].tagValue]"
}
]
}
}
},
"parameters": {
"tags": {
"type": "Array",
"metadata": {
"displayName": "tags",
"description": "The tags to apply to the resources."
},
"defaultValue": [
{
"tagName": "Environment",
"tagValue": "Production"
},
{
"tagName": "Department",
"tagValue": "IT"
}
]
}
}
}