Skip to content

Instantly share code, notes, and snippets.

@quintindk
Created June 19, 2021 11:08
Show Gist options
  • Save quintindk/ef184a10731dca75a96d13bdf35c0151 to your computer and use it in GitHub Desktop.
Save quintindk/ef184a10731dca75a96d13bdf35c0151 to your computer and use it in GitHub Desktop.
Azure Policy to apply naming conventions
{
"mode": "Indexed",
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"notequals": "Microsoft.Resources/subscriptions/resourceGroups"
},
{
"anyOf": [
{
"count": {
"value": [
"ai",
"kv",
"sql",
"app",
"search"
],
"name": "pattern",
"where": {
"anyOf": [
{
"value": "[split(field('name'), '-')[0]]",
"like": "[current('pattern')]"
},
{
"value": "[count(split(field('name'), '-'))]",
"equals": 1
}
]
}
},
"notEquals": 1
},
{
"count": {
"value": [
"dev",
"prod"
],
"name": "pattern",
"where": {
"anyOf": [
{
"value": "[last(split(field('name'), '-'))]",
"like": "[current('pattern')]"
},
{
"value": "[count(split(field('name'), '-'))]",
"equals": 1
}
]
}
},
"notEquals": 1
}
]
}
],
"then": {
"effect": "deny"
}
},
"parameters": {}
}
}
@Knightrain0
Copy link

Could you proved an update on this, please? When trying to use it I receive the following error "The inner exception 'The function 'count' defined in policy is invalid."

I could see this having great potential.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment