Search code examples
azureazure-resource-managerazure-api-managementazure-resource-group

ARM Template API Management Deploy PolicyContent


I am trying to use ARM templates to deploy my API management service and have everything working except policyContent. Basically it wants the policyContent as "Json escaped Xml Encoded contents of the Policy." This is very hard to maintain and was trying to find a way to take an XML file and inject the contents into this string, or some better way. I would like not to have to write a program to maintain these strings because it feels like something that shouldn't be so complicated.

Policy Reference

Example with string

{ "name": "policy", "type": "Microsoft.ApiManagement/service/apis/policies", "apiVersion": "2017-03-01", "properties": { "policyContent": "string" } }


Solution

  • You can maintain your policies into an XML file and reference it like this:

    {
        "apiVersion": "2018-01-01",
        "name": "policy",
        "type": "Microsoft.ApiManagement/service/policies",
        "properties": {
            "policyContent": "[concat(parameters('repoBaseUrl'), '/policy.xml')]",
            "contentFormat": "rawxml-link"
        },
        "dependsOn": [
            "[resourceId('Microsoft.ApiManagement/service/', parameters('ApimServiceName'))]"
        ]
    }
    

    Your policy.xml file must be available online and will look like this:

    <policies>
        <inbound>
            <rate-limit calls="3" renewal-period="10" />
            <base />
        </inbound>
        <outbound>
            <base />
        </outbound>
        <backend>
            <base />
        </backend>
        <on-error>
            <base />
        </on-error>
    </policies>