Azure / api-management-policy-snippets

Re-usable examples of Azure API Management policies
MIT License
345 stars 157 forks source link

PolicyFragment ARM Template deployment fails - The policy fragment is not a valid XML: #95

Open karlrissland opened 2 years ago

karlrissland commented 2 years ago

Bicep Code

param APIMName string

resource policyFragment2 'Microsoft.ApiManagement/service/policyFragments@2021-12-01-preview' = { 
  name: '${APIMName}/SetBasicAuthHeader'
  properties: {
    description: 'Sample desc'
    format: 'xml'
    value: './SetBasicAuthHeader.xml'
  }
}

Fragment Simplified to bare minimum

<fragment>
</fragment>

CLI command to deploy

az deployment group create --resource-group APIM --template-file singlepolicyfragmentdeploy.bicep --parameters APIMName=karlrissapim

Error

{"status":"Failed","error":{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\": \"ValidationError\",\r\n \"message\": \"The policy fragment is not a valid XML: Data at the root level is invalid. Line 1, position 1.\",\r\n \"details\": null\r\n }\r\n}"}]}}

Additional Information We tried deploying from an Azure Storage account in case it needed a URI to reference the policy fragment, failed with the same error message.

We manually created a policy fragment in the portal, then saved the configuration to the repository and cloned the repository locally to inspect the policy fragment to see if there was a documentation bug and the fragment structure was different, the repository does not contain policy fragments so we were unable to view.

We also tried both format types, XML and RawXML.

Lastly, we also compiled bicep to arm and tried again, receiving the same error message.

brwilkinson commented 1 year ago

had a similar question below and found an answer

    format: 'xml'
    value: loadTextContent('loadtextcontent/fragment-request-context-data.xml')