I have a simple Azure Policy that should check if all API-management URL’s are lowercase (Display Name and API Url Suffix), but violations still pass the check, so obviously the policy is incorrect.
I am new to writing my own Azure Policies… Does anyone have an idea what could be wrong?
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.ApiManagement/service/apis"
},
{
"anyOf": [
{
"field": "Microsoft.ApiManagement/service/apis/path",
"notEquals": "[toLower(string(field('Microsoft.ApiManagement/service/apis/path')))]"
},
{
"field": "Microsoft.ApiManagement/service/apis/displayName",
"notEquals": "[toLower(string(field('Microsoft.ApiManagement/service/apis/displayName')))]"
}
]
}
]
}
}
2
Answers
According to Microsoft (https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules) this is by design:
The last comment is probably the reason an Azure Policy cannot be used to check for casing of several fields.
Here is the updated
Azure Policy
checks whether the API management display name and URL are lowercase. If either the display name or the path is not lowercase, it is considered non-compliant otherwise, it is compliant.The display name is located within the properties of API management.
Azure Policy:
Compliance result