Azure Policy not working (check for lowercase APIM Url)

78 views Asked by At

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')))]"
              }
            ]
          }
        ]
      }
}
1

There are 1 answers

11
Venkat V On

Azure Policy not working (check for lowercase APIM Url)

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.

enter image description here

Azure Policy:

{
  "mode": "All",
  "policyRule": {
    "if": {
      "allOf": [
        {
          "field": "type",
          "equals": "Microsoft.ApiManagement/service/apis"
        },
        {
          "anyOf": [
            {
              "not": {
                "field": "Microsoft.ApiManagement/service/apis/path",
                "equals": "[toLower(string(field('Microsoft.ApiManagement/service/apis/path')))]"
              }
            },
            {
              "not": {
                "field": "Microsoft.ApiManagement/service/properties/displayName",
                "equals": "[toLower(string(field('Microsoft.ApiManagement/service/properties/displayName')))]"
              }
            }
          ]
        }
      ]
    },
    "then": {
      "effect": "audit"
    }
  },
  "parameters": {}
}

Compliance result

enter image description here