1212# https://www.terraform.io/docs/providers/aws/r/lb_target_group_attachment.html
1313# https://www.terraform.io/docs/providers/aws/d/acm_certificate.html
1414#
15- # Only support TCP, HTTP, or HTTPS for now. Not both HTTP and HTTPS in single call?
1615# TODO Future:
1716# Multiple LBs ?
1817
@@ -118,43 +117,6 @@ resource "aws_lb" "network" {
118117 */
119118}
120119
121- /*
122- resource "aws_lb" "this" {
123- count = "${module.enabled.value}"
124- name = "${module.label.id_32}"
125- internal = "${var.internal}"
126- load_balancer_type = "${var.type}"
127- #enable_deletion_protection = "${}"
128- idle_timeout = "${var.idle_timeout}"
129- #ip_address_type = "${}"
130- # TODO: not supported for `network`
131- #security_groups = ["${var.security_groups}"]
132- subnets = ["${var.subnets}"]
133- tags = "${module.label.tags}"
134- /* Not supported for `network`
135- access_logs {
136- bucket = "${var.log_bucket_name}"
137- prefix = "${var.log_location_prefix}"
138- enabled = "${module.enable_logging.value}"
139- }
140- */
141- /*
142- subnet_mapping {
143- subnet_id = "${}"
144- allocation_id = "${}"
145- }
146- */
147- /*
148- timeouts {
149- create =
150- delete =
151- update =
152- }
153- *//*
154- depends_on = ["aws_s3_bucket.log_bucket"]
155- }
156- */
157-
158120data "aws_iam_policy_document" "bucket_policy" {
159121 count = " ${
160122 module . enabled . value &&
@@ -223,8 +185,7 @@ locals {
223185 #all_app_ports = "${concat(var.http_instance_ports, var.https_instance_ports)}"
224186}
225187*/
226- # TODO: Support creating multiple
227- # change to 1 resource with list of maps (port, proto?) to create
188+
228189resource "aws_lb_target_group" "application-http" {
229190 count = " ${
230191 module . enabled . value &&
@@ -258,19 +219,19 @@ resource "aws_lb_target_group" "application-http" {
258219 }
259220 tags = " ${ module . label . tags } "
260221}
222+
261223resource "aws_lb_target_group" "application-https" {
262224 count = " ${
263225 module . enabled . value &&
264226 var . type == " application" &&
265227 contains (var. lb_protocols , " HTTPS" )
266- ? length (compact (split (" ," , local. instance_https_ports ))) : 0 } " # "${length(local.all_ports)}"
228+ ? length (compact (split (" ," , local. instance_https_ports ))) : 0 } "
267229 name = " ${ join (" -" ,
268230 list (substr (module. label . id_org ,0 ,26 <= length (module. label . id_org ) ? 26 : length (module. label . id_org ))),
269231 list (element (compact (split (" ," ,local. instance_https_ports )), count. index ))
270232 )} "
271233 port = " ${ element (compact (split (" ," ,local. instance_https_ports )), count. index )} "
272234 protocol = " HTTP"
273- # count.index <= length(var.http_instance_ports) ? "HTTP" : "HTTPS"
274235 vpc_id = " ${ var . vpc_id } "
275236 # deregistration_delay = "${}"
276237 # target_type = "${}"
@@ -292,6 +253,7 @@ resource "aws_lb_target_group" "application-https" {
292253 }
293254 tags = " ${ module . label . tags } "
294255}
256+
295257resource "aws_lb_target_group" "network" {
296258 count = " ${
297259 module . enabled . value &&
@@ -316,22 +278,16 @@ resource "aws_lb_target_group" "network" {
316278 tags = " ${ module . label . tags } "
317279}
318280
319- # TODO: change to 1 resource with list of maps (port, proto?, target group, ssl) to create
320- # lookup ssl cert arn from ACM
321- # use lb_listener_rule for additional ports
322- # Up to 3 listener types (TCP or (HTTP/HTTPS))
323281resource "aws_lb_listener" "http" {
324282 count = " ${
325283 module . enabled . value &&
326284 var . type == " application" &&
327285 contains (var. lb_protocols , " HTTP" )
328286 ? length (compact (split (" ," , local. lb_http_ports ))) : 0 } "
329- # load_balancer_arn = "${aws_lb.this.arn}" # "${coalesce(aws_lb.application.arn, aws_lb.network.arn)}"
330- load_balancer_arn = " ${ coalesce (aws_lb. application . arn , aws_lb. network . arn )} "
287+ load_balancer_arn = " ${ element (concat (aws_lb. application . * . arn , aws_lb. network . * . arn , list (" " )), 0 )} "
331288 port = " ${ element (compact (split (" ," ,local. lb_http_ports )), count. index )} "
332289 protocol = " HTTP"
333290 default_action {
334- # target_group_arn = "${aws_lb_target_group.target_group.id}"
335291 target_group_arn = " ${ element (concat (aws_lb_target_group. application-http . * . arn ), count. index )} "
336292 type = " forward"
337293 }
@@ -343,14 +299,12 @@ resource "aws_lb_listener" "https" {
343299 var . type == " application" &&
344300 contains (var. lb_protocols , " HTTPS" )
345301 ? length (compact (split (" ," , local. lb_https_ports ))) : 0 } "
346- # load_balancer_arn = "${aws_lb.this.arn}" # "${coalesce(aws_lb.application.arn, aws_lb.network.arn)}"
347- load_balancer_arn = " ${ coalesce (aws_lb. application . arn , aws_lb. network . arn )} "
302+ load_balancer_arn = " ${ element (concat (aws_lb. application . * . arn , aws_lb. network . * . arn , list (" " )), 0 )} "
348303 port = " ${ element (compact (split (" ," ,local. lb_https_ports )), count. index )} "
349304 protocol = " HTTPS"
350305 certificate_arn = " ${ element (concat (data. aws_acm_certificate . this . * . arn , list (" " )), 0 )} "
351306 ssl_policy = " ${ var . security_policy } "
352307 default_action {
353- # target_group_arn = "${aws_lb_target_group.target_group.id}"
354308 target_group_arn = " ${ element (concat (aws_lb_target_group. application-https . * . arn ), count. index )} "
355309 type = " forward"
356310 }
@@ -361,8 +315,7 @@ resource "aws_lb_listener" "network" {
361315 module . enabled . value &&
362316 var . type == " network"
363317 ? length (compact (split (" ," , local. lb_tcp_ports ))) : 0 } "
364- # load_balancer_arn = "${aws_lb.this.arn}" # "${coalesce(aws_lb.application.arn, aws_lb.network.arn)}"
365- load_balancer_arn = " ${ coalesce (aws_lb. application . arn , aws_lb. network . arn )} "
318+ load_balancer_arn = " ${ element (concat (aws_lb. application . * . arn , aws_lb. network . * . arn , list (" " )), 0 )} "
366319 port = " ${ element (compact (split (" ," ,local. lb_tcp_ports )), count. index )} "
367320 protocol = " TCP"
368321 default_action {
0 commit comments