Scroll to top
© 2024, Global Digital Services LLC.

Deploying Azure API Management with Terraform


Fernando Noguera - April 19, 2023 - 0 comments

API Management is a powerful Azure service that allows developers to create, publish, manage, and secure APIs quickly and easily. With the help of Terraform, an open-source infrastructure as code tool, it’s possible to deploy and manage API Management resources programmatically. In this article, we will explore how to deploy Azure API Management with Terraform.

Pre requisites before getting started with deploying Azure API Management with Terraform, you need to ensure that you have the following:

  1. An Azure subscription.
  2. A Terraform installation.
  3. An Azure API Management instance.

Step 1: Set up Terraform environment The first step is to set up the Terraform environment. You can download Terraform from the official website, and then install it on your local machine. Once installed, you’ll need to set up the Azure provider for Terraform. You can do this by creating a new file called provider.tf and adding the following code:

provider "azurerm" {
version = "2.76.0"
features {}
}

This code specifies that we are using the azurerm provider version 2.76.0, which is the latest stable release at the time of writing this article.

Step 2: Define the API Management resource The next step is to define the API Management resource using Terraform. To do this, create a new file called apim.tf and add the following code:

resource "azurerm_api_management" "apim" {
name = "apim-demo"
location = "eastus"
resource_group_name = "apim-rg"

publisher_name = "My Company"
publisher_email = "admin@mycompany.com"

sku_name = "Developer_1"
publisher_visibility = "Public"

tags = {
environment = "dev"
}
}

In this code, we are creating a new azurerm_api_management resource called apim with the following properties:

  • name: The name of the API Management instance.
  • location: The location of the API Management instance.
  • resource_group_name: The name of the resource group where the API Management instance will be deployed.
  • publisher_name: The name of the publisher of the APIs.
  • publisher_email: The email address of the publisher of the APIs.
  • sku_name: The SKU of the API Management instance.
  • publisher_visibility: The visibility of the APIs.
  • tags: The tags to be applied to the API Management instance.

Step 3: Apply the Terraform configuration Now that we have defined the API Management resource using Terraform, we can apply the configuration by running the following command:

terraform init
terraform plan
terraform apply

The terraform init command initializes the Terraform environment and downloads any necessary plugins. The terraform plan command shows a preview of the changes that will be made to the infrastructure, and the terraform apply command applies the changes.

Once the deployment is complete, you should be able to see the newly created API Management instance in the Azure portal.

Conclusion In this article, we have explored how to deploy Azure API Management with Terraform. By defining the API Management resource using Terraform, we can easily create and manage API Management instances programmatically. This allows us to automate the deployment of API Management resources and ensure that our infrastructure is consistent and reproducible.

Contact us for more information or visit our blog.

Related posts