From f4b038fa0b2b7391491a28075c7f013bfa05ab02 Mon Sep 17 00:00:00 2001 From: Lakshan-Banneheke Date: Wed, 14 Aug 2024 12:41:39 +0530 Subject: [PATCH 1/4] Add multi method api operation module --- .../api_management_api_operation_primary.tf | 51 +++++++++++ .../api_management_api_operation_secondary.tf | 51 +++++++++++ .../locals.tf | 22 +++++ .../variables.tf | 91 +++++++++++++++++++ .../versions.tf | 27 ++++++ 5 files changed, 242 insertions(+) create mode 100644 modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/api_management_api_operation_primary.tf create mode 100644 modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/api_management_api_operation_secondary.tf create mode 100644 modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/locals.tf create mode 100644 modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf create mode 100644 modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/versions.tf diff --git a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/api_management_api_operation_primary.tf b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/api_management_api_operation_primary.tf new file mode 100644 index 00000000..3b70527b --- /dev/null +++ b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/api_management_api_operation_primary.tf @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +resource "azurerm_api_management_api_operation" "api_management_api_operation_primary" { + for_each = var.methods + operation_id = join("-", [var.api_operation_abbreviation, var.api_operation_id, lower(each.value)]) + api_name = var.api_name + api_management_name = var.primary_api_management_name + resource_group_name = var.resource_group_name + display_name = var.display_name + method = each.value + url_template = var.url_template + + dynamic "template_parameter" { + for_each = var.template_parameters + + content { + name = template_parameter.value.name + type = template_parameter.value.type + required = template_parameter.value.required + description = template_parameter.value.description + } + } +} + +resource "azurerm_api_management_api_operation_policy" "api_management_api_operation_policy_primary" { + for_each = azurerm_api_management_api_operation.api_management_api_operation_primary + api_name = each.value.api_name + api_management_name = each.value.api_management_name + resource_group_name = var.resource_group_name + operation_id = each.value.operation_id + xml_content = templatefile( + lookup(var.method_specific_policy_map, each.value.method, var.default_policy_object)[local.policy_xml_template_file_path], + lookup(var.method_specific_policy_map, each.value.method, var.default_policy_object)[local.policy_xml_template_vars] + ) +} diff --git a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/api_management_api_operation_secondary.tf b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/api_management_api_operation_secondary.tf new file mode 100644 index 00000000..ca9fea20 --- /dev/null +++ b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/api_management_api_operation_secondary.tf @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +resource "azurerm_api_management_api_operation" "api_management_api_operation_secondary" { + for_each = var.methods + operation_id = join("-", [var.api_operation_abbreviation, var.api_operation_id, lower(each.value)]) + api_name = var.api_name + api_management_name = var.secondary_api_management_name + resource_group_name = var.resource_group_name + display_name = var.display_name + method = each.value + url_template = var.url_template + + dynamic "template_parameter" { + for_each = var.template_parameters + + content { + name = template_parameter.value.name + type = template_parameter.value.type + required = template_parameter.value.required + description = template_parameter.value.description + } + } +} + +resource "azurerm_api_management_api_operation_policy" "api_management_api_operation_policy_secondary" { + for_each = azurerm_api_management_api_operation.api_management_api_operation_secondary + api_name = each.value.api_name + api_management_name = each.value.api_management_name + resource_group_name = var.resource_group_name + operation_id = each.value.operation_id + xml_content = templatefile( + lookup(var.method_specific_policy_map, each.value.method, var.default_policy_object)[local.policy_xml_template_file_path], + lookup(var.method_specific_policy_map, each.value.method, var.default_policy_object)[local.policy_xml_template_vars] + ) +} diff --git a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/locals.tf b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/locals.tf new file mode 100644 index 00000000..8d30564f --- /dev/null +++ b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/locals.tf @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +locals { + policy_xml_template_file_path = "policy_xml_template_file_path" + policy_xml_template_vars = "policy_xml_template_vars" +} diff --git a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf new file mode 100644 index 00000000..6839283b --- /dev/null +++ b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +variable "api_operation_abbreviation" { + description = "Abbreviation for the API operation" + type = string + default = "api-op" +} + +variable "api_operation_id" { + description = "A unique identifier for the API operation" + type = string +} + +variable "api_name" { + description = "Name of the API where this API Operation should be created" + type = string +} + +variable "primary_api_management_name" { + description = "Name of the Primary API Management Service where the API exists" + type = string +} + +variable "secondary_api_management_name" { + description = "Name of the Secondary API Management Service where the API exists" + type = string +} + +variable "resource_group_name" { + description = "The Name of the Resource Group in which the API Management Service exists." + type = string +} + +variable "display_name" { + description = "Display name of the API operation" + type = string +} + +variable "methods" { + description = "HTTP method used for the API operation" + type = set(string) +} + +variable "url_template" { + description = "URL template for the API operation, which may include parameters" + type = string +} + +variable "template_parameters" { + description = "Template parameters for the API operation" + type = list(object({ + name = string + type = string + required = bool + description = string + })) + default = [] +} + +variable "default_policy_object" { + description = "Map of default to policy template path and variables" + type = object({ + policy_xml_template_file_path = string + policy_xml_template_vars = any + }) +} + +variable "method_specific_policy_map" { + description = "Map of method to policy map" + type = map(object({ + policy_xml_template_file_path = string + policy_xml_template_vars = any + })) + default = {} +} diff --git a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/versions.tf b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/versions.tf new file mode 100644 index 00000000..85b9621c --- /dev/null +++ b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/versions.tf @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +terraform { + required_version = ">= 0.14" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 3.80.0" + } + } +} From b9ad4b2f2cf30100dd602fb713afa70ff97c9bfa Mon Sep 17 00:00:00 2001 From: Lakshan-Banneheke Date: Wed, 14 Aug 2024 13:47:55 +0530 Subject: [PATCH 2/4] Update API module required versions to 0.14.10 --- .../versions.tf | 2 +- .../API-Management-API-Operation-With-Failover/versions.tf | 2 +- modules/azurerm/API-Management-API-Operation/versions.tf | 2 +- modules/azurerm/API-Management-API-With-Failover/versions.tf | 2 +- modules/azurerm/API-Management-API/versions.tf | 2 +- modules/azurerm/API-Management/versions.tf | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/versions.tf b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/versions.tf index 85b9621c..31ade662 100644 --- a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/versions.tf +++ b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/versions.tf @@ -17,7 +17,7 @@ */ terraform { - required_version = ">= 0.14" + required_version = ">= 0.14.10" required_providers { azurerm = { source = "hashicorp/azurerm" diff --git a/modules/azurerm/API-Management-API-Operation-With-Failover/versions.tf b/modules/azurerm/API-Management-API-Operation-With-Failover/versions.tf index 85b9621c..31ade662 100644 --- a/modules/azurerm/API-Management-API-Operation-With-Failover/versions.tf +++ b/modules/azurerm/API-Management-API-Operation-With-Failover/versions.tf @@ -17,7 +17,7 @@ */ terraform { - required_version = ">= 0.14" + required_version = ">= 0.14.10" required_providers { azurerm = { source = "hashicorp/azurerm" diff --git a/modules/azurerm/API-Management-API-Operation/versions.tf b/modules/azurerm/API-Management-API-Operation/versions.tf index 85b9621c..31ade662 100644 --- a/modules/azurerm/API-Management-API-Operation/versions.tf +++ b/modules/azurerm/API-Management-API-Operation/versions.tf @@ -17,7 +17,7 @@ */ terraform { - required_version = ">= 0.14" + required_version = ">= 0.14.10" required_providers { azurerm = { source = "hashicorp/azurerm" diff --git a/modules/azurerm/API-Management-API-With-Failover/versions.tf b/modules/azurerm/API-Management-API-With-Failover/versions.tf index 85b9621c..31ade662 100644 --- a/modules/azurerm/API-Management-API-With-Failover/versions.tf +++ b/modules/azurerm/API-Management-API-With-Failover/versions.tf @@ -17,7 +17,7 @@ */ terraform { - required_version = ">= 0.14" + required_version = ">= 0.14.10" required_providers { azurerm = { source = "hashicorp/azurerm" diff --git a/modules/azurerm/API-Management-API/versions.tf b/modules/azurerm/API-Management-API/versions.tf index 85b9621c..31ade662 100644 --- a/modules/azurerm/API-Management-API/versions.tf +++ b/modules/azurerm/API-Management-API/versions.tf @@ -17,7 +17,7 @@ */ terraform { - required_version = ">= 0.14" + required_version = ">= 0.14.10" required_providers { azurerm = { source = "hashicorp/azurerm" diff --git a/modules/azurerm/API-Management/versions.tf b/modules/azurerm/API-Management/versions.tf index 85b9621c..31ade662 100644 --- a/modules/azurerm/API-Management/versions.tf +++ b/modules/azurerm/API-Management/versions.tf @@ -17,7 +17,7 @@ */ terraform { - required_version = ">= 0.14" + required_version = ">= 0.14.10" required_providers { azurerm = { source = "hashicorp/azurerm" From bef3988d6294b0a2fe072c79eefea1817a30597f Mon Sep 17 00:00:00 2001 From: Lakshan-Banneheke Date: Wed, 14 Aug 2024 13:59:12 +0530 Subject: [PATCH 3/4] Change policy object type to any --- .../variables.tf | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf index 6839283b..5a7b8df9 100644 --- a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf +++ b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf @@ -75,17 +75,11 @@ variable "template_parameters" { variable "default_policy_object" { description = "Map of default to policy template path and variables" - type = object({ - policy_xml_template_file_path = string - policy_xml_template_vars = any - }) + type = any } variable "method_specific_policy_map" { description = "Map of method to policy map" - type = map(object({ - policy_xml_template_file_path = string - policy_xml_template_vars = any - })) + type = any default = {} } From 67823c045e4d0806806da08f7121ad22057d6a6f Mon Sep 17 00:00:00 2001 From: Lakshan-Banneheke Date: Wed, 14 Aug 2024 14:05:12 +0530 Subject: [PATCH 4/4] Change policy object type to any --- .../variables.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf index 5a7b8df9..3074ff3c 100644 --- a/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf +++ b/modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf @@ -75,11 +75,11 @@ variable "template_parameters" { variable "default_policy_object" { description = "Map of default to policy template path and variables" - type = any + type = any } variable "method_specific_policy_map" { description = "Map of method to policy map" - type = any - default = {} + type = any + default = {} }