From 79c3bf0b1c0ff971fd457bd2c4af07249e55c3d4 Mon Sep 17 00:00:00 2001 From: Lakshan-Banneheke Date: Tue, 10 Sep 2024 13:54:03 +0530 Subject: [PATCH 1/2] Add API Policy Fragment modules --- .../api_policy_fragment_primary.tf | 24 ++++++++ .../api_policy_fragment_secondary.tf | 24 ++++++++ .../outputs.tf | 37 +++++++++++++ .../variables.tf | 55 +++++++++++++++++++ .../versions.tf | 27 +++++++++ .../api_management_policy_fragment.tf | 24 ++++++++ .../API-Management-Policy-Fragment/outputs.tf | 27 +++++++++ .../variables.tf | 50 +++++++++++++++++ .../versions.tf | 27 +++++++++ 9 files changed, 295 insertions(+) create mode 100644 modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_primary.tf create mode 100644 modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_secondary.tf create mode 100644 modules/azurerm/API-Management-Policy-Fragment-With-Failover/outputs.tf create mode 100644 modules/azurerm/API-Management-Policy-Fragment-With-Failover/variables.tf create mode 100644 modules/azurerm/API-Management-Policy-Fragment-With-Failover/versions.tf create mode 100644 modules/azurerm/API-Management-Policy-Fragment/api_management_policy_fragment.tf create mode 100644 modules/azurerm/API-Management-Policy-Fragment/outputs.tf create mode 100644 modules/azurerm/API-Management-Policy-Fragment/variables.tf create mode 100644 modules/azurerm/API-Management-Policy-Fragment/versions.tf diff --git a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_primary.tf b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_primary.tf new file mode 100644 index 00000000..dacfdbbc --- /dev/null +++ b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_primary.tf @@ -0,0 +1,24 @@ +/* + * 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_policy_fragment" "api_policy_fragment_primary" { + api_management_id = var.primary_api_management_id + name = join("-", [var.abbreviation, var.name]) + format = var.file_format + value = file(var.xml_template_file_path) +} diff --git a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_secondary.tf b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_secondary.tf new file mode 100644 index 00000000..19654ed6 --- /dev/null +++ b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_secondary.tf @@ -0,0 +1,24 @@ +/* + * 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_policy_fragment" "api_policy_fragment_secondary" { + api_management_id = var.secondary_api_management_id + name = join("-", [var.abbreviation, var.name]) + format = var.file_format + value = templatefile(var.xml_template_file_path, var.xml_template_vars) +} diff --git a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/outputs.tf b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/outputs.tf new file mode 100644 index 00000000..78e01c2a --- /dev/null +++ b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/outputs.tf @@ -0,0 +1,37 @@ +/* + * 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. + */ + +output "primary_policy_fragment_id" { + value = azurerm_api_management_policy_fragment.api_policy_fragment_primary.id + depends_on = [azurerm_api_management_policy_fragment.api_policy_fragment_primary] +} + +output "secondary_policy_fragment_id" { + value = azurerm_api_management_policy_fragment.api_policy_fragment_secondary.id + depends_on = [azurerm_api_management_policy_fragment.api_policy_fragment_secondary] +} + +output "primary_policy_fragment_name" { + value = azurerm_api_management_policy_fragment.api_policy_fragment_primary.name + depends_on = [azurerm_api_management_policy_fragment.api_policy_fragment_primary] +} + +output "secondary_policy_fragment_name" { + value = azurerm_api_management_policy_fragment.api_policy_fragment_secondary.name + depends_on = [azurerm_api_management_policy_fragment.api_policy_fragment_secondary] +} diff --git a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/variables.tf b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/variables.tf new file mode 100644 index 00000000..2462537e --- /dev/null +++ b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/variables.tf @@ -0,0 +1,55 @@ +/* + * 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 "abbreviation" { + description = "Abbreviation for the API Policy Fragment" + type = string + default = "api-policy-fragment" +} + +variable "name" { + description = "Name of the API Policy Fragment" + type = string +} + +variable "primary_api_management_id" { + description = "ID of the Primary API Management Service where the API Policy Fragment is to be created." + type = string +} + +variable "secondary_api_management_id" { + description = "ID of the Secondary API Management Service where the API Policy Fragment is to be created." + type = string +} + +variable "file_format" { + description = "Format of the API Policy Fragment" + type = string + default = "xml" +} + +variable "xml_template_file_path" { + description = "The path to the policy XML template file" + type = string +} + +variable "xml_template_vars" { + description = "The variables to pass to the policy XML template" + type = any + default = {} +} diff --git a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/versions.tf b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/versions.tf new file mode 100644 index 00000000..31ade662 --- /dev/null +++ b/modules/azurerm/API-Management-Policy-Fragment-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.10" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 3.80.0" + } + } +} diff --git a/modules/azurerm/API-Management-Policy-Fragment/api_management_policy_fragment.tf b/modules/azurerm/API-Management-Policy-Fragment/api_management_policy_fragment.tf new file mode 100644 index 00000000..df3c3f15 --- /dev/null +++ b/modules/azurerm/API-Management-Policy-Fragment/api_management_policy_fragment.tf @@ -0,0 +1,24 @@ +/* + * 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_policy_fragment" "api_management_policy_fragment" { + api_management_id = var.api_management_id + name = join("-", [var.abbreviation, var.name]) + format = var.file_format + value = templatefile(var.xml_template_file_path, var.xml_template_vars) +} diff --git a/modules/azurerm/API-Management-Policy-Fragment/outputs.tf b/modules/azurerm/API-Management-Policy-Fragment/outputs.tf new file mode 100644 index 00000000..1d7829f8 --- /dev/null +++ b/modules/azurerm/API-Management-Policy-Fragment/outputs.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. + */ + +output "id" { + value = azurerm_api_management_policy_fragment.api_management_policy_fragment.id + depends_on = [azurerm_api_management_policy_fragment.api_management_policy_fragment] +} + +output "name" { + value = azurerm_api_management_policy_fragment.api_management_policy_fragment.name + depends_on = [azurerm_api_management_policy_fragment.api_management_policy_fragment] +} diff --git a/modules/azurerm/API-Management-Policy-Fragment/variables.tf b/modules/azurerm/API-Management-Policy-Fragment/variables.tf new file mode 100644 index 00000000..44045587 --- /dev/null +++ b/modules/azurerm/API-Management-Policy-Fragment/variables.tf @@ -0,0 +1,50 @@ +/* + * 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 "abbreviation" { + description = "Abbreviation for the API Policy Fragment" + type = string + default = "api-policy-frag" +} + +variable "name" { + description = "Name of the API Policy Fragment" + type = string +} + +variable "api_management_id" { + description = "ID of the API Management Service where the API Policy Fragment is to be created." + type = string +} + +variable "file_format" { + description = "Format of the API Policy Fragment" + type = string + default = "xml" +} + +variable "xml_template_file_path" { + description = "The path to the policy XML template file" + type = string +} + +variable "xml_template_vars" { + description = "The variables to pass to the policy XML template" + type = any + default = {} +} diff --git a/modules/azurerm/API-Management-Policy-Fragment/versions.tf b/modules/azurerm/API-Management-Policy-Fragment/versions.tf new file mode 100644 index 00000000..31ade662 --- /dev/null +++ b/modules/azurerm/API-Management-Policy-Fragment/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.10" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 3.80.0" + } + } +} From 8cd0a295f9b880ee20ae143b01ed0c3317dc088e Mon Sep 17 00:00:00 2001 From: Lakshan-Banneheke Date: Tue, 10 Sep 2024 15:11:48 +0530 Subject: [PATCH 2/2] Add API Policy Fragment modules --- .../api_policy_fragment_primary.tf | 2 +- .../outputs.tf | 7 +------ .../variables.tf | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_primary.tf b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_primary.tf index dacfdbbc..fac01e40 100644 --- a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_primary.tf +++ b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/api_policy_fragment_primary.tf @@ -20,5 +20,5 @@ resource "azurerm_api_management_policy_fragment" "api_policy_fragment_primary" api_management_id = var.primary_api_management_id name = join("-", [var.abbreviation, var.name]) format = var.file_format - value = file(var.xml_template_file_path) + value = templatefile(var.xml_template_file_path, var.xml_template_vars) } diff --git a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/outputs.tf b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/outputs.tf index 78e01c2a..f57b5ade 100644 --- a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/outputs.tf +++ b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/outputs.tf @@ -26,12 +26,7 @@ output "secondary_policy_fragment_id" { depends_on = [azurerm_api_management_policy_fragment.api_policy_fragment_secondary] } -output "primary_policy_fragment_name" { +output "policy_fragment_name" { value = azurerm_api_management_policy_fragment.api_policy_fragment_primary.name depends_on = [azurerm_api_management_policy_fragment.api_policy_fragment_primary] } - -output "secondary_policy_fragment_name" { - value = azurerm_api_management_policy_fragment.api_policy_fragment_secondary.name - depends_on = [azurerm_api_management_policy_fragment.api_policy_fragment_secondary] -} diff --git a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/variables.tf b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/variables.tf index 2462537e..05e90aeb 100644 --- a/modules/azurerm/API-Management-Policy-Fragment-With-Failover/variables.tf +++ b/modules/azurerm/API-Management-Policy-Fragment-With-Failover/variables.tf @@ -40,7 +40,7 @@ variable "secondary_api_management_id" { variable "file_format" { description = "Format of the API Policy Fragment" type = string - default = "xml" + default = "rawxml" } variable "xml_template_file_path" {