I’m trying to add endpoints from 2 Swagger.json files to an existing common API management API via Terraform.
Common API definition:
resource "azurerm_api_management_api" "test_api" {
provider = azurerm.test
name = "test"
api_management_name = var.apim_name
resource_group_name = var.common_rg
display_name = "test"
description = "test APIM"
path = "test"
revision = "1"
protocols = ["https"]
subscription_key_parameter_names {
header = "Ocp-Apim-Subscription-Key"
query = "subscription-key"
}
}
Normally you can just add:
import {
content_format = "openapi+json"
content_value = data.test_swagger.content
}
But it only accepts 1 file.
I could obviously merge multiple Swaggers using Powershell or use Az cli to do import multiple files, but if there’s a way to do it via Terraform it would be a cleaner solution.
I tried playing with creating multiple azurerm_api_management_api resources and referencing test_api via source_api_id.
Also tried creating a azurerm_api_management_api_schema, but turned out it’s not anything I wanted.
Does Terraform support importing (appending) multiple openapi jsons?
2
Answers
Since the above solution didn't work for me, I came up with a powershell script wrapped into a null_resource, which works nice.
One thing to remember is the -Force flag, which basically will overwrite some objects if there are duplicates. For me it was ProblemDetails component.
The requirement you mentioned is not properly supported by terraform this is because of Azure API mangement provider only supports one import at a time per API resource.
This importing referencing as single openAPI/Swagger file which doesnt included more than one. If you still have multiple file better to merge them into single file as merged file and use in terraform
configuration:
deployment:
Refer:
https://learn.microsoft.com/en-us/azure/api-management/azure-openai-api-from-specification