Skip to content

Commit

Permalink
Merge pull request #92 from Lakshan-Banneheke/apim
Browse files Browse the repository at this point in the history
Add multi method api operation module
  • Loading branch information
Lakshan-Banneheke authored Aug 14, 2024
2 parents 6878c22 + 67823c0 commit 4cb31b1
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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]
)
}
Original file line number Diff line number Diff line change
@@ -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]
)
}
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* 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 = any
}

variable "method_specific_policy_map" {
description = "Map of method to policy map"
type = any
default = {}
}
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

terraform {
required_version = ">= 0.14"
required_version = ">= 0.14.10"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
Expand Down
2 changes: 1 addition & 1 deletion modules/azurerm/API-Management-API-Operation/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

terraform {
required_version = ">= 0.14"
required_version = ">= 0.14.10"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

terraform {
required_version = ">= 0.14"
required_version = ">= 0.14.10"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
Expand Down
2 changes: 1 addition & 1 deletion modules/azurerm/API-Management-API/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

terraform {
required_version = ">= 0.14"
required_version = ">= 0.14.10"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
Expand Down
2 changes: 1 addition & 1 deletion modules/azurerm/API-Management/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

terraform {
required_version = ">= 0.14"
required_version = ">= 0.14.10"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
Expand Down

0 comments on commit 4cb31b1

Please sign in to comment.