Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_api_management_api_operation_policy: xml validation failed #7345

Closed
DimaPachynin opened this issue Jun 16, 2020 · 2 comments · Fixed by #7639
Closed

azurerm_api_management_api_operation_policy: xml validation failed #7345

DimaPachynin opened this issue Jun 16, 2020 · 2 comments · Fixed by #7639

Comments

@DimaPachynin
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform (and AzureRM Provider) Version

terraform 0.12.26 x64
"azurerm" (hashicorp/azurerm) 2.14.0
"template" (hashicorp/template) 2.1.2

Affected Resource(s)

  • azurerm_api_management_api_operation_policy

Terraform Configuration Files

resource "azurerm_api_management_api_operation_policy" "XXXPolicy" {
  api_name            = azurerm_api_management_api_operation.XXXApi.api_name
  api_management_name = azurerm_api_management_api_operation.XXXApi.api_management_name
  resource_group_name = azurerm_api_management_api_operation.XXXApi.resource_group_name
  operation_id        = azurerm_api_management_api_operation.XXXApi.operation_id

  xml_content = local.XXXPolicy
}

XML Policy

<policies>
    <inbound>
        <base />
        <cors>
            <allowed-origins>
                <origin>*</origin>
            </allowed-origins>
            <allowed-methods>
                <method>*</method>
            </allowed-methods>
            <allowed-headers>
                <header>*</header>
            </allowed-headers>
        </cors>
        <send-request mode="new" response-variable-name="getCertResponse" timeout="10" ignore-error="false">
            <set-url>XXX</set-url>
            <set-method>GET</set-method>
            <set-header name="Authorization" exists-action="override">
                <value>@(context.Request.Headers.GetValueOrDefault("Authorization",""))</value>
            </set-header>
        </send-request>
        <set-header name="Authorization" exists-action="override">
            <value>@{
                var responseObj = ((IResponse)context.Variables["getCertResponse"]).Body.As<JObject>();
                var jwt = (string)responseObj["payload"];
                return $"Bearer {jwt}";}</value>
        </set-header>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

Debug Output

Panic Output

Expected Behavior

It works fine for azurerm_api_management_api_policy. Expected the same for azurerm_api_management_api_operation_policy . Policy works fine if you apply it via Azure portal.

example:

resource "azurerm_api_management_api_policy" "YYYPolicy" {
  api_name            = azurerm_api_management_api.YYYApi.name
  api_management_name = azurerm_api_management.api.name
  resource_group_name = local.azurerm_resource_group_name

  xml_content = local.XXXPolicy
}

Actual Behavior

 Error: creating or updating API Operation Policy (Resource Group "RG-xxx" / API Management Service "apim-xxx" / API "XXXApi" / Operation "AccessLevelGet"): apimanagement.APIOperationPolicyClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="ValidationError" Message="One or more fields contain incorrect values:" Details=[{"code":"ValidationError","message":"The 'JObject' start tag on line 24 position 94 does not match the end tag of 'value'. Line 27, position 15.","target":"representation"}]
 
   on apimanagements.tf line 1373, in resource "azurerm_api_management_api_operation_policy" "XXXPolicy":
 1373: resource "azurerm_api_management_api_operation_policy" "XXXPolicy" {

Steps to Reproduce

  1. terraform apply

Important Factoids

Checked on Azure East US 2 location.
Works fine via portal.

References

@ghost
Copy link

ghost commented Jul 10, 2020

This has been released in version 2.18.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.18.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Aug 9, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@hashicorp hashicorp locked and limited conversation to collaborators Aug 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants