piku
piku

Reputation: 613

Execution sequence to execute bicep for apim and consumption logic app

I have a requirement to implement APIM - policies --> consumption logic app(http triggered). I have achieved this from the UI however, I have to create bicep for the same

I am using bicep to implement this functionality and not sure how to achieve this in the same execution.

Also, I have just started with bicep therefore please advice on the best practises to follow while creating these resources/functionality and deploying to subscriptions/PROD.

Upvotes: 0

Views: 45

Answers (1)

Vinay B
Vinay B

Reputation: 2401

Execution sequence to execute bicep for apim and consumption logic app

To have configuration to use Bicep that create resources for APIM, policies, and a consumption logic app you need logic app with its HTTP trigger apply the AAD policy with the application and IP restrictions and set up the APIM with frontend and backend policies, including 'JWT token' and linking to the logic app. This is the basic structure. This configuration can be achived by refering to document attached.

To achive this involves creating dependencies between the logic app and APIM, even though APIM is created after the logic app you can either use the dependsOn to achieve this requriement of sequencial order.

A sample configuration setup looking like this mentioned below

bicep configuration:

resource apimPolicy 'Microsoft.ApiManagement/service/apis/policies@2021-08-01' = {
  parent: apimApi
  name: 'policy'
  properties: {
    value: '''
    <policies>
      <inbound>
        <base />
        <validate-jwt header-name="Authorization"
                      require-scheme="Bearer"
                      failed-validation-httpcode="401"
                      failed-validation-error-message="Unauthorized">
          <openid-config url="https://login.microsoftonline.com/${tenantId}/v2.0/.well-known/openid-configuration" />
          <required-claims>
            <claim name="appid">
              <value>${expectedAppId}</value>
            </claim>
          </required-claims>
        </validate-jwt>
      </inbound>
      <backend>
        <set-backend-service base-url="${logicAppCallbackUrl}" />
      </backend>
      <outbound>
        <base />
      </outbound>
      <on-error>
        <base />
      </on-error>
    </policies>
    '''
  }
  dependsOn: [
    apimApi
  ]
}

For more rest of the configuration for logicapps, jwt-policy apim, apim policies info on bicep configuration

you can also refer to these microsoft documentations mentioned below

https://learn.microsoft.com/en-us/azure/templates/microsoft.logic/workflows?pivots=deployment-language-bicep

https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/resource-dependencies

Upvotes: 0

Related Questions