Created
June 19, 2021 11:08
-
-
Save quintindk/ef184a10731dca75a96d13bdf35c0151 to your computer and use it in GitHub Desktop.
Azure Policy to apply naming conventions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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": {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.