Deploy and monitor API Management instance using Bicep Language
  • 06 Jan 2023
  • 2 Minutes to read
  • Dark
    Light
  • PDF

Deploy and monitor API Management instance using Bicep Language

  • Dark
    Light
  • PDF

#ServerlessTips - Azure Bicep
Author: Dave Rendon Microsoft MVP

The purpose of this article is to help you deploy and configure monitoring of an API Management instance in your environment using Infrastructure-as-Code with Azure Bicep.

Azure Bicep is a domain-specific language (DSL) that uses a declarative syntax to deploy Azure resources.

Bicep is an abstraction on top of Azure Resource Manager (ARM) templates to define Azure resources using declarative Infrastructure as Code.

This article will show how you can deploy deploy and configure monitoring of an API Management instance using Azure Bicep, a Domain Specific Language (DSL) for deploying Azure resources declaratively.

Prerequisites

• An Active Azure account: You can create an account for free.
Azure Bicep is installed on your local machine.
• Azure PowerShell. See: Install Azure PowerShell.
• A resource group in your Azure subscription

Let’s get started!

Solution Overview

We will author a Bicep template that creates and configures monitoring of an API Management instance. The solution will include the following files:

• 📄 main.bicep: This is the Bicep template
• 📄 azuredeploy.parameters.json: This parameter file contains the values to use for deploying your Bicep template.

2. Azure Bicep Template — parameters

Create a new file in your working directory and name it main.bicep . We will define the following parameters:

description('The email address of the owner of the service')
@minLength(1)
param apiManagementPublisherEmail string

@description('The name of the owner of the service')
@minLength(1)
param apiManagementPublisherName string

@description('The pricing tier of this API Management service')
@allowed([
  'Developer'
  'Premium'
])
param apiManagementSku string = 'Premium'

@description('The instance size of this API Management service.')
param apiManagementSkuCount int = 1

@description('Select the SKU for your workspace')
@allowed([
  'pergb2018'
  'Premium'
])
param omsSku string = 'pergb2018'

@description('Location for all resources.')
param location string = resourceGroup().location

3. Azure Bicep Template — variables

We will define the following variables:

var apiManagementServiceName = 'apiservice-azinsdr'
var omsWorkspaceName = 'azinsdr-workspace'

4. Azure Bicep Template — resources

We will define the following resources:

resource apiManagementService 'Microsoft.ApiManagement/service@2021-01-01-preview' = {
  name: apiManagementServiceName
  location: location
  sku: {
    name: apiManagementSku
    capacity: apiManagementSkuCount
  }
  identity: {
    type: 'SystemAssigned'
  }
  properties: {
    publisherEmail: apiManagementPublisherEmail
    publisherName: apiManagementPublisherName
  }
}

resource omsWorkspace 'Microsoft.OperationalInsights/workspaces@2020-08-01' = {
  name: omsWorkspaceName
  location: location
  properties: {
    sku: {
      name: omsSku
    }
  }
}

resource apiManagementServiceName_Microsoft_Insights_service 'Microsoft.ApiManagement/service/providers/diagnosticSettings@2021-05-01-preview' = {
  name: '${apiManagementServiceName}/Microsoft.Insights/service'
  properties: {
    workspaceId: omsWorkspace.id
    logs: [
      {
        category: 'GatewayLogs'
        enabled: true
      }
    ]
  }
  dependsOn: [
    apiManagementService
  ]
}

5. Parameters file

Create a new file named azuredeploy.parameters.json. The code below shows the definition of the parameters file:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "apiManagementPublisherEmail": {
        "value": "yourmail@outlook.com"
      },
      "apiManagementPublisherName": {
        "value": "azinsdr"
      },
      "apiManagementSku": {
        "value": "Premium"
      },
      "apiManagementSkuCount": {
        "value": 1
      },
      "omsSku": {
        "value": "pergb2018"
      },
      "location": {
        "value": "eastus"
      }
    }
  }

6. Azure Bicep Template — Deployment

We will use the command below to deploy our Bicep template:

$date = Get-Date -Format "MM-dd-yyyy"
$rand = Get-Random -Maximum 1000
$deploymentName = "AzInsiderDeployment-"+"$date"+"-"+"$rand"

New-AzResourceGroupDeployment -Name $deploymentName -ResourceGroupName azinsider_demo -TemplateFile .\main.bicep -TemplateParameterFile .\azuredeploy.parameters.json -c

The image below shows the preview of the deployment:

Then we will execute the deployment. The image below shows the deployment output:

You can verify the deployment using the Azure Portal.

Source Code

You can find the code of this solution in the following URL, feel free to contribute!

https://github.com/daveRendon/azinsider/tree/main/application-workloads/deploy-and-monitor-api-management


Was this article helpful?