From 44c6a463cc1d9af4c91297599b551a2f68abcfa5 Mon Sep 17 00:00:00 2001 From: Mohamed Sazni Date: Tue, 9 Dec 2025 15:59:32 +0530 Subject: [PATCH 1/2] Add Traffic Manager Endpoint module with routing methods --- ...ffic_manager_priority_external_endpoint.tf | 35 +++++++++++ .../variables.tf | 60 +++++++++++++++++++ .../versions.tf | 29 +++++++++ 3 files changed, 124 insertions(+) create mode 100644 modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_priority_external_endpoint.tf create mode 100644 modules/azurerm/Traffic-Manager-External-Endpoint/variables.tf create mode 100644 modules/azurerm/Traffic-Manager-External-Endpoint/versions.tf diff --git a/modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_priority_external_endpoint.tf b/modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_priority_external_endpoint.tf new file mode 100644 index 0000000..9a9895f --- /dev/null +++ b/modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_priority_external_endpoint.tf @@ -0,0 +1,35 @@ +# ------------------------------------------------------------------------------------- +# +# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +# +# 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_traffic_manager_external_endpoint" "performace_based_external_endpoint" { + count = var.routing_method == "Performance" ? 1 : 0 + name = var.endpoint_name + profile_id = var.profile_id + target = var.target + endpoint_location = var.endpoint_location + dynamic "custom_header" { + for_each = var.custom_headers + content { + name = custom_header.value.header_name + value = custom_header.value.header_value + } + } + always_serve_enabled = var.always_serve_enabled +} diff --git a/modules/azurerm/Traffic-Manager-External-Endpoint/variables.tf b/modules/azurerm/Traffic-Manager-External-Endpoint/variables.tf new file mode 100644 index 0000000..eeb9b5b --- /dev/null +++ b/modules/azurerm/Traffic-Manager-External-Endpoint/variables.tf @@ -0,0 +1,60 @@ +# ------------------------------------------------------------------------------------- +# +# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +# +# 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 "endpoint_name" { + description = "Name of the endpoint" + type = string +} + +variable "profile_id" { + description = "ID of the traffic manager profile" + type = string +} + +variable "target" { + description = "Target IP or FQDN DNS name" + type = string +} + +variable "routing_method" { + description = "Routing method for the Traffic Manager Profile. Valid values are 'Performance', 'Priority', 'Weighted', 'Geographic', 'Multivalue', 'Subnet'." + type = string +} + +variable "endpoint_location" { + description = "Location of the endpoint. Required for Performance routing method." + type = string + default = "" +} + +variable "custom_headers" { + description = "Custom headers for the endpoint" + type = list(object({ + header_name = string + header_value = string + })) + default = [] +} + +variable "always_serve_enabled" { + description = "Indicates whether the endpoint should always serve traffic, even if it is unhealthy." + type = bool + default = false +} diff --git a/modules/azurerm/Traffic-Manager-External-Endpoint/versions.tf b/modules/azurerm/Traffic-Manager-External-Endpoint/versions.tf new file mode 100644 index 0000000..5fd7f4d --- /dev/null +++ b/modules/azurerm/Traffic-Manager-External-Endpoint/versions.tf @@ -0,0 +1,29 @@ +# ------------------------------------------------------------------------------------- +# +# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +# +# 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.13" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 3.0.0" + } + } +} From ea2cb70c3770f50c42677fd470b819b9b1e44877 Mon Sep 17 00:00:00 2001 From: Mohamed Sazni Date: Tue, 9 Dec 2025 17:15:39 +0530 Subject: [PATCH 2/2] Update configuration --- .../traffic_manager_external_endpoint.tf | 127 ++++++++++++++++++ ...ffic_manager_priority_external_endpoint.tf | 36 ----- .../variables.tf | 54 +++++++- 3 files changed, 174 insertions(+), 43 deletions(-) create mode 100644 modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_external_endpoint.tf delete mode 100644 modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_priority_external_endpoint.tf diff --git a/modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_external_endpoint.tf b/modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_external_endpoint.tf new file mode 100644 index 0000000..5c7e5af --- /dev/null +++ b/modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_external_endpoint.tf @@ -0,0 +1,127 @@ +# ------------------------------------------------------------------------------------- +# +# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. +# +# 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_traffic_manager_external_endpoint" "performance_based_external_endpoint" { + count = var.routing_method == "Performance" ? 1 : 0 + name = var.endpoint_name + profile_id = var.profile_id + target = var.target + endpoint_location = var.endpoint_location + always_serve_enabled = var.always_serve_enabled + enabled = var.enabled + dynamic "custom_header" { + for_each = var.custom_headers + content { + name = custom_header.value.header_name + value = custom_header.value.header_value + } + } +} + +resource "azurerm_traffic_manager_external_endpoint" "weighted_based_external_endpoint" { + count = var.routing_method == "Weighted" ? 1 : 0 + name = var.endpoint_name + profile_id = var.profile_id + target = var.target + weight = var.weight + always_serve_enabled = var.always_serve_enabled + enabled = var.enabled + dynamic "custom_header" { + for_each = var.custom_headers + content { + name = custom_header.value.header_name + value = custom_header.value.header_value + } + } +} + +resource "azurerm_traffic_manager_external_endpoint" "priority_based_external_endpoint" { + count = var.routing_method == "Priority" ? 1 : 0 + name = var.endpoint_name + profile_id = var.profile_id + target = var.target + priority = var.priority + always_serve_enabled = var.always_serve_enabled + enabled = var.enabled + dynamic "custom_header" { + for_each = var.custom_headers + content { + name = custom_header.value.header_name + value = custom_header.value.header_value + } + } +} + +resource "azurerm_traffic_manager_external_endpoint" "geographic_based_external_endpoint" { + count = var.routing_method == "Geographic" ? 1 : 0 + name = var.endpoint_name + profile_id = var.profile_id + target = var.target + geo_mappings = var.geo_mappings + always_serve_enabled = var.always_serve_enabled + enabled = var.enabled + dynamic "custom_header" { + for_each = var.custom_headers + content { + name = custom_header.value.header_name + value = custom_header.value.header_value + } + } +} + +resource "azurerm_traffic_manager_external_endpoint" "multivalue_based_external_endpoint" { + count = var.routing_method == "Multivalue" ? 1 : 0 + name = var.endpoint_name + profile_id = var.profile_id + target = var.target + always_serve_enabled = var.always_serve_enabled + enabled = var.enabled + dynamic "custom_header" { + for_each = var.custom_headers + content { + name = custom_header.value.header_name + value = custom_header.value.header_value + } + } +} + +resource "azurerm_traffic_manager_external_endpoint" "subnet_based_external_endpoint" { + count = var.routing_method == "Subnet" ? 1 : 0 + name = var.endpoint_name + profile_id = var.profile_id + target = var.target + always_serve_enabled = var.always_serve_enabled + enabled = var.enabled + dynamic "subnet" { + for_each = var.subnets + content { + first = subnet.value.first + last = subnet.value.last + scope = subnet.value.scope + } + } + dynamic "custom_header" { + for_each = var.custom_headers + content { + name = custom_header.value.header_name + value = custom_header.value.header_value + } + } +} diff --git a/modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_priority_external_endpoint.tf b/modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_priority_external_endpoint.tf deleted file mode 100644 index 5dad228..0000000 --- a/modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_priority_external_endpoint.tf +++ /dev/null @@ -1,36 +0,0 @@ -# ------------------------------------------------------------------------------------- -# -# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved. -# -# 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_traffic_manager_external_endpoint" "performace_based_external_endpoint" { - count = var.routing_method == "Performance" ? 1 : 0 - name = var.endpoint_name - profile_id = var.profile_id - target = var.target - endpoint_location = var.endpoint_location - dynamic "custom_header" { - for_each = var.custom_headers - content { - name = custom_header.value.header_name - value = custom_header.value.header_value - } - } - always_serve_enabled = var.always_serve_enabled - enabled = var.enabled -} diff --git a/modules/azurerm/Traffic-Manager-External-Endpoint/variables.tf b/modules/azurerm/Traffic-Manager-External-Endpoint/variables.tf index 3309437..e7bf826 100644 --- a/modules/azurerm/Traffic-Manager-External-Endpoint/variables.tf +++ b/modules/azurerm/Traffic-Manager-External-Endpoint/variables.tf @@ -34,14 +34,12 @@ variable "target" { } variable "routing_method" { - description = "Routing method for the Traffic Manager Profile. Valid values are 'Performance', 'Priority', 'Weighted', 'Geographic', 'Multivalue', 'Subnet'." + description = "Routing method for the Traffic Manager Profile. Valid values are 'Performance', 'Priority', 'Weighted', 'Geographic', 'Multivalue', 'Subnet'" type = string -} - -variable "endpoint_location" { - description = "Location of the endpoint. Required for Performance routing method." - type = string - default = "" + validation { + condition = contains(["Performance", "Priority", "Weighted", "Geographic", "Multivalue", "Subnet"], var.routing_method) + error_message = "Routing method must be one of: Performance, Priority, Weighted, Geographic, Multivalue, or Subnet." + } } variable "custom_headers" { @@ -64,3 +62,45 @@ variable "enabled" { type = bool default = true } + +variable "weight" { + description = "Weight of the endpoint. Required for Weighted routing method. Valid values are between 1 and 1000" + type = number + default = 1 +} + +variable "priority" { + description = "Priority of the endpoint. Required for Priority routing method. Valid values are between 1 and 1000" + type = number + default = 1 +} + +variable "endpoint_location" { + description = "Location of the endpoint. Required for Performance routing method. The location must be specified for endpoints of types: 'Performance'" + type = string + default = "" + validation { + condition = ( + var.routing_method != "Performance" || + (var.routing_method == "Performance" && var.endpoint_location != "") + ) + error_message = "endpoint_location must be provided when routing_method is 'Performance'." + } + +} + +variable "geo_mappings" { + description = "A list of Geographic Regions used to distribute traffic. Required for Geographic routing method." + type = list(string) + default = [] +} + +variable "subnets" { + description = "A list of subnets used to distribute traffic. Required for Subnet routing method." + type = list(object({ + first = string + last = optional(string) + scope = optional(string) + })) + default = [] +}