Skip to content

Commit ea2cb70

Browse files
committed
Update configuration
1 parent f0054ae commit ea2cb70

File tree

3 files changed

+174
-43
lines changed

3 files changed

+174
-43
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# -------------------------------------------------------------------------------------
2+
#
3+
# Copyright (c) 2025, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
4+
#
5+
# WSO2 LLC. licenses this file to you under the Apache License,
6+
# Version 2.0 (the "License"); you may not use this file except
7+
# in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
# --------------------------------------------------------------------------------------
20+
21+
resource "azurerm_traffic_manager_external_endpoint" "performance_based_external_endpoint" {
22+
count = var.routing_method == "Performance" ? 1 : 0
23+
name = var.endpoint_name
24+
profile_id = var.profile_id
25+
target = var.target
26+
endpoint_location = var.endpoint_location
27+
always_serve_enabled = var.always_serve_enabled
28+
enabled = var.enabled
29+
dynamic "custom_header" {
30+
for_each = var.custom_headers
31+
content {
32+
name = custom_header.value.header_name
33+
value = custom_header.value.header_value
34+
}
35+
}
36+
}
37+
38+
resource "azurerm_traffic_manager_external_endpoint" "weighted_based_external_endpoint" {
39+
count = var.routing_method == "Weighted" ? 1 : 0
40+
name = var.endpoint_name
41+
profile_id = var.profile_id
42+
target = var.target
43+
weight = var.weight
44+
always_serve_enabled = var.always_serve_enabled
45+
enabled = var.enabled
46+
dynamic "custom_header" {
47+
for_each = var.custom_headers
48+
content {
49+
name = custom_header.value.header_name
50+
value = custom_header.value.header_value
51+
}
52+
}
53+
}
54+
55+
resource "azurerm_traffic_manager_external_endpoint" "priority_based_external_endpoint" {
56+
count = var.routing_method == "Priority" ? 1 : 0
57+
name = var.endpoint_name
58+
profile_id = var.profile_id
59+
target = var.target
60+
priority = var.priority
61+
always_serve_enabled = var.always_serve_enabled
62+
enabled = var.enabled
63+
dynamic "custom_header" {
64+
for_each = var.custom_headers
65+
content {
66+
name = custom_header.value.header_name
67+
value = custom_header.value.header_value
68+
}
69+
}
70+
}
71+
72+
resource "azurerm_traffic_manager_external_endpoint" "geographic_based_external_endpoint" {
73+
count = var.routing_method == "Geographic" ? 1 : 0
74+
name = var.endpoint_name
75+
profile_id = var.profile_id
76+
target = var.target
77+
geo_mappings = var.geo_mappings
78+
always_serve_enabled = var.always_serve_enabled
79+
enabled = var.enabled
80+
dynamic "custom_header" {
81+
for_each = var.custom_headers
82+
content {
83+
name = custom_header.value.header_name
84+
value = custom_header.value.header_value
85+
}
86+
}
87+
}
88+
89+
resource "azurerm_traffic_manager_external_endpoint" "multivalue_based_external_endpoint" {
90+
count = var.routing_method == "Multivalue" ? 1 : 0
91+
name = var.endpoint_name
92+
profile_id = var.profile_id
93+
target = var.target
94+
always_serve_enabled = var.always_serve_enabled
95+
enabled = var.enabled
96+
dynamic "custom_header" {
97+
for_each = var.custom_headers
98+
content {
99+
name = custom_header.value.header_name
100+
value = custom_header.value.header_value
101+
}
102+
}
103+
}
104+
105+
resource "azurerm_traffic_manager_external_endpoint" "subnet_based_external_endpoint" {
106+
count = var.routing_method == "Subnet" ? 1 : 0
107+
name = var.endpoint_name
108+
profile_id = var.profile_id
109+
target = var.target
110+
always_serve_enabled = var.always_serve_enabled
111+
enabled = var.enabled
112+
dynamic "subnet" {
113+
for_each = var.subnets
114+
content {
115+
first = subnet.value.first
116+
last = subnet.value.last
117+
scope = subnet.value.scope
118+
}
119+
}
120+
dynamic "custom_header" {
121+
for_each = var.custom_headers
122+
content {
123+
name = custom_header.value.header_name
124+
value = custom_header.value.header_value
125+
}
126+
}
127+
}

modules/azurerm/Traffic-Manager-External-Endpoint/traffic_manager_priority_external_endpoint.tf

Lines changed: 0 additions & 36 deletions
This file was deleted.

modules/azurerm/Traffic-Manager-External-Endpoint/variables.tf

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,12 @@ variable "target" {
3434
}
3535

3636
variable "routing_method" {
37-
description = "Routing method for the Traffic Manager Profile. Valid values are 'Performance', 'Priority', 'Weighted', 'Geographic', 'Multivalue', 'Subnet'."
37+
description = "Routing method for the Traffic Manager Profile. Valid values are 'Performance', 'Priority', 'Weighted', 'Geographic', 'Multivalue', 'Subnet'"
3838
type = string
39-
}
40-
41-
variable "endpoint_location" {
42-
description = "Location of the endpoint. Required for Performance routing method."
43-
type = string
44-
default = ""
39+
validation {
40+
condition = contains(["Performance", "Priority", "Weighted", "Geographic", "Multivalue", "Subnet"], var.routing_method)
41+
error_message = "Routing method must be one of: Performance, Priority, Weighted, Geographic, Multivalue, or Subnet."
42+
}
4543
}
4644

4745
variable "custom_headers" {
@@ -64,3 +62,45 @@ variable "enabled" {
6462
type = bool
6563
default = true
6664
}
65+
66+
variable "weight" {
67+
description = "Weight of the endpoint. Required for Weighted routing method. Valid values are between 1 and 1000"
68+
type = number
69+
default = 1
70+
}
71+
72+
variable "priority" {
73+
description = "Priority of the endpoint. Required for Priority routing method. Valid values are between 1 and 1000"
74+
type = number
75+
default = 1
76+
}
77+
78+
variable "endpoint_location" {
79+
description = "Location of the endpoint. Required for Performance routing method. The location must be specified for endpoints of types: 'Performance'"
80+
type = string
81+
default = ""
82+
validation {
83+
condition = (
84+
var.routing_method != "Performance" ||
85+
(var.routing_method == "Performance" && var.endpoint_location != "")
86+
)
87+
error_message = "endpoint_location must be provided when routing_method is 'Performance'."
88+
}
89+
90+
}
91+
92+
variable "geo_mappings" {
93+
description = "A list of Geographic Regions used to distribute traffic. Required for Geographic routing method."
94+
type = list(string)
95+
default = []
96+
}
97+
98+
variable "subnets" {
99+
description = "A list of subnets used to distribute traffic. Required for Subnet routing method."
100+
type = list(object({
101+
first = string
102+
last = optional(string)
103+
scope = optional(string)
104+
}))
105+
default = []
106+
}

0 commit comments

Comments
 (0)