-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from Lakshan-Banneheke/apim
Add multi method api operation module
- Loading branch information
Showing
10 changed files
with
241 additions
and
5 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...nagement-API-Operation-Multi-Method-With-Failover/api_management_api_operation_primary.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
) | ||
} |
51 changes: 51 additions & 0 deletions
51
...gement-API-Operation-Multi-Method-With-Failover/api_management_api_operation_secondary.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/locals.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
85 changes: 85 additions & 0 deletions
85
modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {} | ||
} |
27 changes: 27 additions & 0 deletions
27
modules/azurerm/API-Management-API-Operation-Multi-Method-With-Failover/versions.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters