From 77b9273cd980a8c46869a13682139377a7ad20c0 Mon Sep 17 00:00:00 2001 From: zjanura Date: Wed, 6 Mar 2024 12:32:22 +0100 Subject: [PATCH 1/2] schema added into apim simple --- .../azure/api_management_api_simple/main.tf | 10 +++++++++ .../api_management_api_simple/variables.tf | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/modules/azure/api_management_api_simple/main.tf b/modules/azure/api_management_api_simple/main.tf index 010d0736..18e5720f 100644 --- a/modules/azure/api_management_api_simple/main.tf +++ b/modules/azure/api_management_api_simple/main.tf @@ -16,6 +16,7 @@ provider "azurerm" { } locals { + do_schema = var.schema.file_location != null && var.schema.type != null && var.schema.schema_id != null ? true : false } ####################################################### @@ -239,3 +240,12 @@ resource "azurerm_api_management_product_api" "product_api" { api_management_name = var.api_management_name resource_group_name = var.resource_group_name } + +resource "azurerm_api_management_global_schema" "json" { + count = local.do_schema ? 1 : 0 + schema_id = var.schema.schema_id + api_management_name = var.api_management_name + resource_group_name = var.resource_group_name + type = var.schema.type + value = file(var.schema.file_location) +} diff --git a/modules/azure/api_management_api_simple/variables.tf b/modules/azure/api_management_api_simple/variables.tf index f5909a6a..07e773be 100644 --- a/modules/azure/api_management_api_simple/variables.tf +++ b/modules/azure/api_management_api_simple/variables.tf @@ -163,3 +163,24 @@ variable "custom_outbound_policy" { description = "Additional outbound xml policies" default = null } + +variable "schema" { + type = object({ + file_location = optional(string), + type = optional(string), + schema_id = optional(string) + }) + + default = { + file_location = null + type = null + schema_id = null + } + + validation { + condition = ((var.schema.file_location != null && var.schema.type != null && var.schema.schema_id != null) || (var.schema.file_location == null && var.schema.type == null && var.schema.schema_id == null)) + error_message = "schema_id, file_location and type must be provided." + } + + description = "Schema for validation of request" +} From 5901238f9fbbc581d24735922ec4f1a39c6d6d25 Mon Sep 17 00:00:00 2001 From: zjanura Date: Wed, 6 Mar 2024 12:33:13 +0100 Subject: [PATCH 2/2] formatting updated --- modules/azure/api_management_api_simple/variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/azure/api_management_api_simple/variables.tf b/modules/azure/api_management_api_simple/variables.tf index 07e773be..806435d0 100644 --- a/modules/azure/api_management_api_simple/variables.tf +++ b/modules/azure/api_management_api_simple/variables.tf @@ -181,6 +181,6 @@ variable "schema" { condition = ((var.schema.file_location != null && var.schema.type != null && var.schema.schema_id != null) || (var.schema.file_location == null && var.schema.type == null && var.schema.schema_id == null)) error_message = "schema_id, file_location and type must be provided." } - + description = "Schema for validation of request" }