Tim Scriv
Tim Scriv

Reputation: 700

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" } }

Upvotes: 4

Views: 3967

Answers (2)

Sacha Bruttin
Sacha Bruttin

Reputation: 4153

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>

Upvotes: 5

4c74356b41
4c74356b41

Reputation: 72151

Well, the only thing I can think of (because nothing native in arm templates can help you) is read the input from a file and convert it to JSON:

$xml = (Get-Content file -Raw).ToString()
($xml | ConvertTo-Json -Compress) -replace '\\u003c','<' ) -replace '\\u003e','>'

It might work without replacing those unicodes back to <>, no idea.

Upvotes: 2

Related Questions