I’m trying to import a policy to azure api management using a bicep template as follows:
resource allOpsPolicy 'Microsoft.ApiManagement/service/apis/policies@2021-12-01-preview' = {
name: 'policy'
parent: apimapi_v1
properties: {
value: loadTextContent('all-ops-policy.xml')
format: 'xml'
}
}
The content of the all-ops-policy.xml file is as follows:
<policies>
<inbound>
<base />
<choose>
<when condition="@(context.Request.OriginalUrl.ToString().EndsWith("Public") == false)">
<rewrite-uri template="@(String.Concat(context.Request.OriginalUrl.ToString(),"/", "MapServer"))" copy-unmatched-params="false" />
</when>
<otherwise />
</choose>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
When run I get the following error:
One or more fields contain incorrect values: (Code: ValidationError)
- ‘Public’ is an unexpected token. Expecting white space.
Can anyone see where I’m going wrong?
2
Answers
The problem was the value of the format property of the allOpsPolicy resource.
I changed from
to
then it worked!
Thanks to Nisha for solving this one
Please replace the single quotes ` with double quotes ".
It seems there’s also one single quote too much:
Complete policy:
Issue is not reproducable: