I have created a azure policy to validate the name field for resource group objects

Ilfad Hasanovic 5 Reputation points
2023-12-18T11:04:10.01+00:00

I have created a simple azure policy to validate the name field for azure resource group name

when i validate the regex online it works fine

{
  "mode": "All",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.Resources/subscriptions/resourceGroups"
        },
        {
          "not": {
            "field": "name",
            "like": "^[a-zA-Z]{2,5}-[a-zA-Z]+-(prod|dev|test)-[a-zA-Z0-9]+-[0-9]{3}$"
          }
        }
      ]
    },
    "then": {
      "effect": "deny"
    }
  },
  "parameters": {}
}

User's image

Azure Policy
Azure Policy
An Azure service that is used to implement corporate governance and standards at scale for Azure resources.
968 questions
{count} vote

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 18,891 Reputation points
    2023-12-19T09:14:57.1033333+00:00

    @Ilfad Hasanovic Welcome to Microsoft Q & A Community Forum. Kindly note Azure Policy doesn't support RegEx yet. The conditions with Azure Policy where Regex pattern can be used are like, notLike, match, notMatch. While these provide Regex like capabilities, it isn't full Regex support. like/notLike supports * as a wildcard and match/notMatch supports # for a single digit and ? for a single letter. You can combine the conditions with an allOf logical operator for more advanced scenarios. Similar feedback here was shared directly with the responsible Azure feature team. I recommend navigating to the above link and clicking the vote button to raise visibility and priority on this.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.