pulumi-azure icon indicating copy to clipboard operation
pulumi-azure copied to clipboard

Azure API Management policies fail when containing quotes and chevrons, provider should use XmlRaw

Open UnoSD opened this issue 4 years ago • 2 comments

When trying to create an Azure API Management policy containing C# expressions with quotes and chevrons, I get errors, few examples:

Pulumi error

error: creating or updating API Operation Policy: apimanagement.APIOperationPolicyClient#CreateOrUpdate: Failure responding to request: StatusCode=400

Few of the Azure errors in Pulumi log

autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"An error occurred while parsing EntityName. Line 5, position 92.","target":"representation"}]
autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"'=' is an unexpected token. The expected token is ';'. Line 30, position 189.","target":"representation"}]

This seems to be an issue with the Terraform provider used under the hood as in this issue: https://github.com/terraform-providers/terraform-provider-azurerm/issues/3918

It seems to be resolved on the Terraform side so I was wondering if you are using the latest version of the provider under the hood; if not, if this can be updated to resolve the issue and start using XmlRaw as content type.

This is another issue I open on the Terraform repository where they confirm it has been fixed on their side:

https://github.com/terraform-providers/terraform-provider-azurerm/issues/7288

Thank you

UnoSD avatar Jun 22 '20 15:06 UnoSD

@UnoSD can you provide the code you're using that's causing this error?

clstokes avatar Jun 24 '20 16:06 clstokes

@clstokes Thank you for the response. I have abandoned that route and I am uploading the XML using az cli. I had to dig in the old builds and I found the problematic one: https://github.com/UnoSD/UnoCash/commit/9752b1fccdae235fbeb218210a89751e9aa0d692

Any commit before that one is a different attempt using different escape sequences, none of them worked. This is an example of one:

<policies>
    <inbound>
        <base />
        <choose>
            <when condition="@(context.Request.OriginalUrl.Scheme.ToLower() == &#34;http&#34;)">
                <return-response>
                    <set-status code="303" reason="See Other" />
                    <set-header name="Location" exists-action="override">
                        <value>@("%s/" + context.Request.OriginalUrl.Path + context.Request.OriginalUrl.QueryString)</value>
                    </set-header>
                </return-response>
            </when>
        </choose>
        <rate-limit calls="100" renewal-period="300" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

Ideally I should be able to use quotes instead of &#34; like this:

<when condition="@(context.Request.OriginalUrl.Scheme.ToLower() == "http")">

Then, it is just used here:

        ApiPolicy("policy",
                  ApiPolicyArgs(ResourceGroupName = io resourceGroup.Name,
                                ApiManagementName = io apiManagement.Name,
                                ApiName = io api.Name,
                                XmlContent = io apiPolicyXml))

UnoSD avatar Jun 24 '20 18:06 UnoSD