0

I'm having a bit of problem parsing the differences between Azure's name for things and Terraform's name for things, but overall I'm making a good go of it. I am having some specific problems, though. My situation is that someone built the APIM using the Azure portal, and the company now wants to "make it scalable" by using Terraform to build it out. I've got a pretty good riff going - define, plan, import, plan, modify - but there are some parts of Azure APIM that can't map (mentally) to Terraform commands. My first one is this screen right here (the definitions tab of an API in APIM:)

enter image description here

Since I'm still fresh in terms of rep on Stack, I can't actually show the image. But in the portal at the bottom of the API there is a tab called "definitions". I haven't been able to see a) how to "get" them using Azure Powershell, and b) I how to "set" them with Terraform.

Would someone more knowledgeable about AzureRM and Terraform be able to steer me in the right direction please?

Markus Meyer
  • 3,327
  • 10
  • 22
  • 35
crazycga
  • 1
  • 1
  • 1

1 Answers1

0

One of the workaround you can follow to deploy an API management instance with api's.

We have tried to create APIM instance with API,

Here is the sample terraform code that we used you can use it by adding resource name according to your requirement.

example.tf:-

provider "azurerm" {
  features {}
   }                           
  


resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_api_management" "example" {
  name                = "example-apimajmt"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  publisher_name      = "My Company"
  publisher_email     = "company@terraform.io"

  sku_name = "Developer_1"
}

resource "azurerm_api_management_api" "example" {
  name                = "example-apiajmt"
  resource_group_name = azurerm_resource_group.example.name
  api_management_name = azurerm_api_management.example.name
  revision            = "1"
  display_name        = "ajtest API"
  path                = "example"
  protocols           = ["https"]

  

  import {
    content_format = "swagger-link-json"
    content_value  = "http://conferenceapi.azurewebsites.net/?format=json"
  }
}

After creation we can use it for adding tags

/* resource "azurerm_api_management_api_tag" "example" {
      api_id = azurerm_api_management_api.example.id
      name   = "example-tagajmt"
    }*/

Once the terraform apply is done then you will able to get the APIM instance along with the API and their tags after sometimes.

NOTE:- Creation of APIM will take upto 45 minutes.

OUTPUT SCREENSHOT FOR REFERENCE:-

enter image description here

enter image description here enter image description here

For more information with configuration in APIM management by terraform please refer to this HashiCorp| Terraform Registry azurerm_api_management & this Similar SO THREAD|Tag an API in Azure API Management with Terraform.

AjayKumarGhose
  • 4,257
  • 2
  • 4
  • 15