Home > database >  How do I add a new API version via Terraform in Azure API Manager?
How do I add a new API version via Terraform in Azure API Manager?

Time:06-28

I would like to add a new API version under the existing API that is already there. I can do that easily via the Portal UI however, can someone please guide me to how to achieve this via Terraform? Any sample snippet would be helpful.

I am trying to reverse engineer v1, v2 of this into Terraform. Thanks.

enter image description here

CodePudding user response:

Terraform supports API Version Set and reference it in the API:

version - (Optional) The Version number of this API, if this API is versioned.
version_set_id - (Optional) The ID of the Version Set which this API is associated with.

NOTE: When version is set, version_set_id must also be specified

resource "azurerm_api_management_api_version_set" "example" {
  name                = "example-apimapi"
  resource_group_name = var.resource_group_name
  api_management_name = var.apim_name
  display_name        = "ExampleAPIVersionSet"
  versioning_scheme   = "Segment"
}

resource "azurerm_api_management_api" "example" {
  name                = "example-api"
  resource_group_name = var.resource_group_name
  api_management_name = var.apim_name
  revision            = "1"
  display_name        = "Example API"
  path                = "example_me"
  protocols           = ["https"]
  service_url         = "https://conferenceapi.azurewebsites.net/"
  version             = "v1"
  version_set_id      = azurerm_api_management_api_version_set.example.id


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

There's a tutorial for doing it the Portal: Tutorial: Publish multiple versions of your API

When you create multiple versions, the Azure portal creates a version set, which represents a set of versions for a single logical API. Select the name of an API that has multiple versions. The Azure portal displays its Version set. You can customize the Name and Description of a virtual set.

  • Related