Forum Discussion
gregory_esnaud
Mar 13, 2023Copper Contributor
Checking that old and new ressources are configured with a tag with specific case
 Hello Azure community!     I'm configuring an Azure Policy to check presence of a tag on new and old ressources.     Checking the presence only was quite easy:      policy_rule = <<RULE
{
"if": {
"al...
- Mar 15, 2023I've found the answer (or one of... but honestly I think it's the only one 😄) and, again, thanks for your time! Here is the code: policy_rule = <<RULE { "if": { "allOf": [ { "value": "[contains(string(field('tags')),parameters('tagName'))]", "notMatch": "True" }, { "field": "type", "equals": "Microsoft.Compute/virtualMachines" } ] }, "then": { "effect": "[parameters('effect')]" } } RULEThen, if you `tagName` is **RigorousMakesMeHappy** and whatever the tagValue is you will be compliant or not with: - RigorousMakesMeHappy: ✅ (compliant) 
- rigorousMakesMeHappy: ❌ (not compliant) 
- RigorousMakesMeHapPY: ❌ 
- qsdfqsdfqsfd: ❌ 
- yougettheidea: ❌ 
 
gregory_esnaud
Mar 15, 2023Copper Contributor
I've found the answer (or one of... but honestly I think it's the only one 😄) and, again, thanks for your time!
Here is the code:
policy_rule = <<RULE
{
 "if": {
  "allOf": [
  {
    "value": "[contains(string(field('tags')),parameters('tagName'))]",
    "notMatch": "True"
  },
  {
    "field": "type",
    "equals": "Microsoft.Compute/virtualMachines"
  }
  ]
},
  "then": {
    "effect": "[parameters('effect')]"
  }
}
RULE
Then, if you `tagName` is **RigorousMakesMeHappy** and whatever the tagValue is you will be compliant or not with:
- RigorousMakesMeHappy: ✅ (compliant) 
- rigorousMakesMeHappy: ❌ (not compliant) 
- RigorousMakesMeHapPY: ❌ 
- qsdfqsdfqsfd: ❌ 
- yougettheidea: ❌