Ubaldo Quintero
Ubaldo Quintero

Reputation: 189

How to reference a file in azure bicep /policies

When defining an Azure API Management policy in a Bicep or ARM template, the format of the policy value may be set to rawxml (and rawxml-link) or xml (and xml-link). I know what the rawxml and xml formats are, but I rather have a separated file i.e. api-policy.xml and call it from the module bicep file. Is this even possible?

if I try putting the local path like that it would just return "The provided link is malformed."

resource service_api_management_name_policy 'Microsoft.ApiManagement/service/apis/policies@2021-08-01' = {
  parent: service_internal_api
  name: 'policy'
  properties: {
    value: '/api-policy.xml'
    format: 'rawxml-link'
  }
}

Upvotes: 3

Views: 1948

Answers (1)

algreat
algreat

Reputation: 9002

You can load policy text from file and operate with it as string (ex. replace some template values):

resource apiPolicy 'Microsoft.ApiManagement/service/apis/policies@2021-08-01' = {
  parent: api
  name: 'policy'
  properties: {
    format: 'rawxml'
    value: loadTextContent('./policies/policies.xml')
  }
}

Also you can try policy fragments: https://learn.microsoft.com/en-us/azure/templates/microsoft.apimanagement/service/policyfragments?tabs=bicep

Upvotes: 4

Related Questions