@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.
I have created a azure policy to validate the name field for resource group objects
Ilfad Hasanovic
5
Reputation points
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": {}
}
1 answer
Sort by: Most helpful
-
SwathiDhanwada-MSFT 18,891 Reputation points
2023-12-19T09:14:57.1033333+00:00