Forum Discussion

gregory_esnaud's avatar
gregory_esnaud
Copper Contributor
Mar 13, 2023
Solved

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...
  • gregory_esnaud's avatar
    Mar 15, 2023

    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: ❌

     

Resources