Skip to content

Commit f834505

Browse files
authored
feat: Allow to configure the protocol of the target group (#10)
1 parent fd52a3a commit f834505

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ resource "aws_lb_target_group" "lb_http_tgs" {
143143
}
144144
name = "${var.name_prefix}-http-${each.value.target_group_port}"
145145
port = each.value.target_group_port
146-
protocol = "HTTP"
146+
protocol = lookup(each.value, "target_group_protocol", "") == "" ? "HTTP" : each.value.target_group_protocol
147147
vpc_id = var.vpc_id
148148
deregistration_delay = var.deregistration_delay
149149
slow_start = var.slow_start
@@ -160,7 +160,7 @@ resource "aws_lb_target_group" "lb_http_tgs" {
160160
enabled = var.target_group_health_check_enabled
161161
interval = var.target_group_health_check_interval
162162
path = var.target_group_health_check_path
163-
protocol = "HTTP"
163+
protocol = lookup(each.value, "target_group_protocol", "") == "" ? "HTTP" : each.value.target_group_protocol
164164
timeout = var.target_group_health_check_timeout
165165
healthy_threshold = var.target_group_health_check_healthy_threshold
166166
unhealthy_threshold = var.target_group_health_check_unhealthy_threshold
@@ -186,7 +186,7 @@ resource "aws_lb_target_group" "lb_https_tgs" {
186186
}
187187
name = "${var.name_prefix}-https-${each.value.target_group_port}"
188188
port = each.value.target_group_port
189-
protocol = "HTTPS"
189+
protocol = lookup(each.value, "target_group_protocol", "") == "" ? "HTTPS" : each.value.target_group_protocol
190190
vpc_id = var.vpc_id
191191
deregistration_delay = var.deregistration_delay
192192
slow_start = var.slow_start
@@ -203,7 +203,7 @@ resource "aws_lb_target_group" "lb_https_tgs" {
203203
enabled = var.target_group_health_check_enabled
204204
interval = var.target_group_health_check_interval
205205
path = var.target_group_health_check_path
206-
protocol = "HTTPS"
206+
protocol = lookup(each.value, "target_group_protocol", "") == "" ? "HTTPS" : each.value.target_group_protocol
207207
timeout = var.target_group_health_check_timeout
208208
healthy_threshold = var.target_group_health_check_healthy_threshold
209209
unhealthy_threshold = var.target_group_health_check_unhealthy_threshold

variables.tf

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,9 @@ variable "https_ports" {
118118
/*
119119
Other options for listeners (The same are valid also for https_ports variable):
120120
121-
Redirect (Force HTTPS):
122121
variable "http_ports" {
123-
description = "Map containing objects with two fields, listener_port and the target_group_port to redirect HTTP requests"
124-
type = map
122+
description = "Map containing objects to define listeners behaviour based on type field. If type field is `forward`, include listener_port and the target_group_port. For `redirect` type, include listener port, host, path, port, protocol, query and status_code. For `fixed-response`, include listener_port, content_type, message_body and status_code"
123+
type = map(any)
125124
default = {
126125
force_https = {
127126
type = "redirect"
@@ -135,10 +134,11 @@ Redirect (Force HTTPS):
135134
}
136135
}
137136
}
137+
138138
Fixed response:
139139
variable "http_ports" {
140-
description = "Map containing objects with two fields, listener_port and the target_group_port to redirect HTTP requests"
141-
type = map
140+
description = "Map containing objects to define listeners behaviour based on type field. If type field is `forward`, include listener_port and the target_group_port. For `redirect` type, include listener port, host, path, port, protocol, query and status_code. For `fixed-response`, include listener_port, content_type, message_body and status_code"
141+
type = map(any)
142142
default = {
143143
fixed_response = {
144144
type = "fixed-response"
@@ -149,6 +149,22 @@ Fixed response:
149149
}
150150
}
151151
}
152+
153+
Additionally, you can have an HTTPS listener forwarding traffic to an HTTP target group by setting `target_group_protocol` to `HTTP`. The default for `https_ports` variable is `HTTPS`:
154+
155+
variable "https_ports" {
156+
description = "Map containing objects to define listeners behaviour based on type field. If type field is `forward`, include listener_port and the target_group_port. For `redirect` type, include listener port, host, path, port, protocol, query and status_code. For `fixed-response`, include listener_port, content_type, message_body and status_code"
157+
type = map(any)
158+
default = {
159+
https_listener_to_http_target_group = {
160+
type = "forward"
161+
listener_port = 443
162+
target_group_port = 80
163+
target_group_protocol = HTTP
164+
}
165+
}
166+
}
167+
152168
*/
153169

154170
variable "http_ingress_cidr_blocks" {

0 commit comments

Comments
 (0)