skip to Main Content

I configured APIM in Bicep like this:

resource apiManagement 'Microsoft.ApiManagement/service@2019-12-01' = {
  name: appName
  location: location
  sku: {
    name: 'Developer'
    capacity: 1
  }
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    publisherEmail: publisherEmail
    publisherName: publisherName
  }
  resource policy 'policies@2021-01-01-preview' = {
    name: 'allApis'
    properties: {
      value: allOperationsPolicy
      format: 'xml'
    }
  }
}

And I can create ‘api-read’ API with some policy using syntax like this:

resource apiRead 'Microsoft.ApiManagement/service/apis@2021-01-01-preview' = {
  parent: apiManagement
  name: 'api-read'
  properties: {
    displayName: 'API Read'
    subscriptionRequired: true
    path: 'read'
    protocols: [
      'https'
    ]
    isCurrent: true
    authenticationSettings: {
      oAuth2: {
        authorizationServerId: authServer.name
      }
    }
  }
  resource policyAllOperationsRead 'policies@2021-01-01-preview' = {
    name: 'policy'
    properties: {
      value: myPolicyHere
      format: 'xml'
    }
  }
}

But how can I add policy to All API’s (global policy) using Bicep, to have it here?

screenshot of APIM

I have tried like this:

resource apiManagement 'Microsoft.ApiManagement/service@2019-12-01' = {
  name: appName
  location: location
  sku: {
    name: 'Developer'
    capacity: 1
  }
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    publisherEmail: publisherEmail
    publisherName: publisherName
  }
  
}

resource policy 'Microsoft.ApiManagement/service/apis/policies@2021-01-01-preview' = {
  parent: apiManagement
  name: 'allApis'
  properties: {
    value: allOperationsPolicy
    format: 'xml'
  }
}

But I got error:

The property "parent" expected a value of type "Microsoft.ApiManagement/service/apis" but the provided value is of type "Microsoft.ApiManagement/service@2019-12-01"

2

Answers


  1. Chosen as BEST ANSWER

    After all I was able to do it like that:

    resource apiManagement 'Microsoft.ApiManagement/service@2019-12-01' = {
      name: appName
      location: location
      sku: {
        name: 'Developer'
        capacity: 1
      }
      identity: {
        type: 'SystemAssigned'
      }
      properties: {
        publisherEmail: publisherEmail
        publisherName: publisherName
      }
      resource policy 'policies@2021-01-01-preview' = {
        name: 'policy'
        properties: {
          value: allOperationsPolicy
          format: 'xml'
        }
      }
    }
    

    Note that name can only be "policy"


  2. Looking at the documentation, policies can be added for all apis like that:

    resource policy 'Microsoft.ApiManagement/service/policies@2021-01-01-preview' = {
      parent: apiManagement
      name: 'allApis'
      properties: {
        value: allOperationsPolicy
        format: 'xml'
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search