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')))]"
}
]
}
]
}
}
According to Microsoft (https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/resource-name-rules) this is by design:
Resource and resource group names are case-insensitive unless specifically noted in the valid characters column.
When using various APIs to retrieve the name for a resource or resource group, the returned value may have different casing than what you originally specified for the name. The returned value may even display different case values than what is listed in the valid characters table.
Always perform a case-insensitive comparison of names.
The last comment is probably the reason an Azure Policy cannot be used to check for casing of several fields.