From 1a87fdbc2f50e35d6df566516911bce7e16960ef Mon Sep 17 00:00:00 2001 From: "ZOI\\graham.geary" Date: Sat, 21 Apr 2018 16:44:16 +0200 Subject: [PATCH 1/7] #4 corrected "lb_security_group_ids" typo, #5 Updated README.md re. adding multiple targets --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 198b800..f2384c1 100644 --- a/README.md +++ b/README.md @@ -66,12 +66,13 @@ https_health_check_matcher = "200-299" #default = 200 (Success codes) https_target_group_deregistration_delay = 30 #default = 300 (seconds) https_target_group_stickiness_enabled = true #default set to false https_target_group_stickiness_cookie_duration = 8640 #default 8640 seconds (1 day) +``` -# VPC ID and the target instance are valid for both target groups and need only be set once: - +### VPC ID and Target Instance +Are valid for both target groups and need only be set once. Multiple targets should be specified in a comma separated string without spaces. A maximum of 8 targets are currently supported in this module: +```hcl vpc_id = "vpc-a01234bc" -target_id = "i-00123456789123abc" - +target_id = "i-00123456789123aaa,i-00123456789123bbb,i-00123456789123ccc" ``` @@ -184,12 +185,13 @@ By default **all IP addresses are permitted** for both the HTTP and HTTPS securi rule_allow_lb_https_listener_traffic_in_cidr_blocks = ["172.16.0.0/16", "192.168.0.0/24"] ``` -#### Load Balancer Optional Arguments +### Load Balancer Optional Arguments +#### Adding Already Existing Security Groups Additional security groups can be added to the load balancer: ```hcl - lb_security_groups = ["sg-12345678", "sg-abc87654"] + lb_security_group_ids = ["sg-12345678", "sg-abc87654"] ``` Idle timeout (default = 60) for the load balancer, defining if http2 is enabled (default = true) and enabling deletion protection (default = false) can also be set as follows: ```hcl From 80a2daeb1f1a5edee529642e1da167307f047af2 Mon Sep 17 00:00:00 2001 From: "ZOI\\graham.geary" Date: Sat, 21 Apr 2018 16:54:41 +0200 Subject: [PATCH 2/7] #5 Support for adding up to 8 targets to HTTP target groups --- http_target_groups.tf | 53 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/http_target_groups.tf b/http_target_groups.tf index 492ab07..083bd00 100644 --- a/http_target_groups.tf +++ b/http_target_groups.tf @@ -35,11 +35,54 @@ resource "aws_lb_target_group" "tg_http" { #tags = https://github.com/hashicorp/terraform/issues/15226 } -# Attach target to http target group(s) -resource "aws_lb_target_group_attachment" "attach_http_tg" { - count = "${var.lb_http_listener ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" - +# Attach up to 8 targets to http target group(s) +# aws_alb_target_group_attachment errors out when multiple instance id's used +# Workaround until https://github.com/terraform-providers/terraform-provider-aws/issues/647 is solved +resource "aws_lb_target_group_attachment" "attach_http_tg_target1" { + count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 1 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 0)}" + port = "${element(var.http_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_http_tg_target2" { + count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 2 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 1)}" + port = "${element(var.http_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_http_tg_target3" { + count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 3 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 2)}" + port = "${element(var.http_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_http_tg_target4" { + count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 4 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 3)}" + port = "${element(var.http_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_http_tg_target5" { + count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 5 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 4)}" + port = "${element(var.http_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_http_tg_target6" { + count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 6 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 5)}" + port = "${element(var.http_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_http_tg_target7" { + count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 7 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 6)}" + port = "${element(var.http_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_http_tg_target8" { + count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 8 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" - target_id = "${var.target_id}" + target_id = "${element(split(",", var.target_ids), 7)}" port = "${element(var.http_target_group_ports, count.index)}" } From e4a488108cff7aefbcfcdbdc0d8bb0f749161258 Mon Sep 17 00:00:00 2001 From: "ZOI\\graham.geary" Date: Sat, 21 Apr 2018 16:55:00 +0200 Subject: [PATCH 3/7] #5 Support for adding up to 8 targets to HTTPS target groups --- https_target_groups.tf | 59 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/https_target_groups.tf b/https_target_groups.tf index a99fbb5..926d6c4 100644 --- a/https_target_groups.tf +++ b/https_target_groups.tf @@ -33,11 +33,62 @@ resource "aws_lb_target_group" "tg_https" { } } -# Attach target to https target group(s) -resource "aws_lb_target_group_attachment" "attach_https_tg" { - count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" +# Attach up to 8 targets to https target group(s) +# aws_alb_target_group_attachment errors out when multiple instance id's used +# Workaround until https://github.com/terraform-providers/terraform-provider-aws/issues/647 is solved +resource "aws_lb_target_group_attachment" "attach_https_tg_target1" { + count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 1 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + + target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 0)}" + port = "${element(var.https_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_https_tg_target2" { + count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 2 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + + target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 1)}" + port = "${element(var.https_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_https_tg_target3" { + count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 3 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + + target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 2)}" + port = "${element(var.https_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_https_tg_target4" { + count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 4 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + + target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 3)}" + port = "${element(var.https_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_https_tg_target5" { + count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 5 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + + target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 4)}" + port = "${element(var.https_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_https_tg_target6" { + count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 6 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + + target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 5)}" + port = "${element(var.https_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_https_tg_target7" { + count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 7 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + + target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" + target_id = "${element(split(",", var.target_ids), 6)}" + port = "${element(var.https_target_group_ports, count.index)}" +} +resource "aws_lb_target_group_attachment" "attach_https_tg_target8" { + count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 8 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" - target_id = "${var.target_id}" + target_id = "${element(split(",", var.target_ids), 7)}" port = "${element(var.https_target_group_ports, count.index)}" } From 38c578018272e88e975067952998453278bf0628 Mon Sep 17 00:00:00 2001 From: "ZOI\\graham.geary" Date: Sat, 21 Apr 2018 16:55:47 +0200 Subject: [PATCH 4/7] #5 Modified "target_id" variable/parameter to "target_ids" --- variables_shared_target_group.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/variables_shared_target_group.tf b/variables_shared_target_group.tf index 533fb0b..981e2ff 100644 --- a/variables_shared_target_group.tf +++ b/variables_shared_target_group.tf @@ -1,5 +1,5 @@ -# HTTP/HTTPS target group ID -variable "target_id" { - description = "Instance ID for the target group" +# HTTP/HTTPS target group IDs +variable "target_ids" { + description = "Instance IDs for the target group(s)" default = "" } From 700dc84d2aacdd5191800bcd3df6df02340db6b3 Mon Sep 17 00:00:00 2001 From: "ZOI\\graham.geary" Date: Sat, 21 Apr 2018 17:05:34 +0200 Subject: [PATCH 5/7] #4 #5 Updated change log for release version 0.0.2 --- CHANGELOG.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e87e7a3..0989391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,18 @@ BACKWARDS INCOMPATIBILITIES / NOTES: NEW FEATURES: * The HTTPS listener now supports offloading to HTTP target groups. -Activated by setting parameter "lb_https_offloading=true" +(Activated by setting parameter "lb_https_offloading=true") +* Ability to add multiple targets to target groups IMPROVEMENTS: -* Added the following output values: lb_name, lb_arn, lb_arn_suffix, lb_dns_name, lb_zone_id +* Added the following output values: + * lb_name + * lb_arn + * lb_arn_suffix + * lb_dns_name + * lb_zone_id BUG FIXES: -* N/A +* Corrected "lb_security_group_ids" typo in README.md From 374677277483be33a15d013d18c032580fcc3dfc Mon Sep 17 00:00:00 2001 From: "ZOI\\graham.geary" Date: Sat, 21 Apr 2018 23:34:35 +0200 Subject: [PATCH 6/7] #5 moved target group attachment counts to locals.tf --- http_target_groups.tf | 16 ++++++++-------- https_target_groups.tf | 24 ++++++++---------------- locals.tf | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/http_target_groups.tf b/http_target_groups.tf index 083bd00..f22ea68 100644 --- a/http_target_groups.tf +++ b/http_target_groups.tf @@ -39,49 +39,49 @@ resource "aws_lb_target_group" "tg_http" { # aws_alb_target_group_attachment errors out when multiple instance id's used # Workaround until https://github.com/terraform-providers/terraform-provider-aws/issues/647 is solved resource "aws_lb_target_group_attachment" "attach_http_tg_target1" { - count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 1 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + count = "${local.http_target_id_1}" target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 0)}" port = "${element(var.http_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_http_tg_target2" { - count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 2 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + count = "${local.http_target_id_2}" target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 1)}" port = "${element(var.http_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_http_tg_target3" { - count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 3 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + count = "${local.http_target_id_3}" target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 2)}" port = "${element(var.http_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_http_tg_target4" { - count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 4 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + count = "${local.http_target_id_4}" target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 3)}" port = "${element(var.http_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_http_tg_target5" { - count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 5 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + count = "${local.http_target_id_5}" target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 4)}" port = "${element(var.http_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_http_tg_target6" { - count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 6 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + count = "${local.http_target_id_6}" target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 5)}" port = "${element(var.http_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_http_tg_target7" { - count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 7 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + count = "${local.http_target_id_7}" target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 6)}" port = "${element(var.http_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_http_tg_target8" { - count = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 8 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + count = "${local.http_target_id_8}" target_group_arn = "${element(aws_lb_target_group.tg_http.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 7)}" port = "${element(var.http_target_group_ports, count.index)}" diff --git a/https_target_groups.tf b/https_target_groups.tf index 926d6c4..b506358 100644 --- a/https_target_groups.tf +++ b/https_target_groups.tf @@ -37,57 +37,49 @@ resource "aws_lb_target_group" "tg_https" { # aws_alb_target_group_attachment errors out when multiple instance id's used # Workaround until https://github.com/terraform-providers/terraform-provider-aws/issues/647 is solved resource "aws_lb_target_group_attachment" "attach_https_tg_target1" { - count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 1 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - + count = "${local.https_target_id_1}" target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 0)}" port = "${element(var.https_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_https_tg_target2" { - count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 2 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - + count = "${local.https_target_id_2}" target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 1)}" port = "${element(var.https_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_https_tg_target3" { - count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 3 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - + count = "${local.https_target_id_3}" target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 2)}" port = "${element(var.https_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_https_tg_target4" { - count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 4 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - + count = "${local.https_target_id_4}" target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 3)}" port = "${element(var.https_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_https_tg_target5" { - count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 5 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - + count = "${local.https_target_id_5}" target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 4)}" port = "${element(var.https_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_https_tg_target6" { - count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 6 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - + count = "${local.https_target_id_6}" target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 5)}" port = "${element(var.https_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_https_tg_target7" { - count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 7 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - + count = "${local.https_target_id_7}" target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 6)}" port = "${element(var.https_target_group_ports, count.index)}" } resource "aws_lb_target_group_attachment" "attach_https_tg_target8" { - count = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 8 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - + count = "${local.https_target_id_8}" target_group_arn = "${element(aws_lb_target_group.tg_https.*.arn, count.index)}" target_id = "${element(split(",", var.target_ids), 7)}" port = "${element(var.https_target_group_ports, count.index)}" diff --git a/locals.tf b/locals.tf index b6f05b7..12d2dd6 100644 --- a/locals.tf +++ b/locals.tf @@ -9,4 +9,25 @@ locals { lb_private_subnet_ids = ["${var.lb_private_subnet_ids}"] lb_public_subnet_ids = ["${var.lb_public_subnet_ids}"] lb_subnet_ids = ["${split(",", var.lb_internal ? join(",", local.lb_private_subnet_ids) : join(",", local.lb_public_subnet_ids))}"] + + # HTTP target group attachment + http_target_id_1 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 1 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + http_target_id_2 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 2 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + http_target_id_3 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 3 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + http_target_id_4 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 4 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + http_target_id_5 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 5 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + http_target_id_6 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 6 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + http_target_id_7 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 7 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + http_target_id_8 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 8 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + + # HTTPS target group attachment + https_target_id_1 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 1 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + https_target_id_2 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 2 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + https_target_id_3 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 3 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + https_target_id_4 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 4 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + https_target_id_5 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 5 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + https_target_id_6 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 6 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + https_target_id_7 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 7 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + https_target_id_8 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 8 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + } From 05cb11afc1671893d6d0eeaa88f7db612091b446 Mon Sep 17 00:00:00 2001 From: "ZOI\\graham.geary" Date: Tue, 24 Apr 2018 13:50:42 +0200 Subject: [PATCH 7/7] #5 aggregated locals for target group attachment --- locals.tf | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/locals.tf b/locals.tf index 12d2dd6..372028e 100644 --- a/locals.tf +++ b/locals.tf @@ -11,23 +11,25 @@ locals { lb_subnet_ids = ["${split(",", var.lb_internal ? join(",", local.lb_private_subnet_ids) : join(",", local.lb_public_subnet_ids))}"] # HTTP target group attachment - http_target_id_1 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 1 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" - http_target_id_2 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 2 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" - http_target_id_3 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 3 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" - http_target_id_4 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 4 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" - http_target_id_5 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 5 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" - http_target_id_6 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 6 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" - http_target_id_7 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 7 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" - http_target_id_8 = "${var.lb_http_listener ? "${length(split(",", var.target_ids)) >= 8 ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" :0}" + http_tg_attachment_conditionals = "${var.lb_http_listener ? "${length(var.http_target_group_names) == "${length(var.http_target_group_ports)}" ? "${length(var.http_target_group_names)}" : 0}" :0}" + http_target_id_1 = "${length(split(",", var.target_ids)) >= 1 ? "${local.http_tg_attachment_conditionals}" :0}" + http_target_id_2 = "${length(split(",", var.target_ids)) >= 2 ? "${local.http_tg_attachment_conditionals}" :0}" + http_target_id_3 = "${length(split(",", var.target_ids)) >= 3 ? "${local.http_tg_attachment_conditionals}" :0}" + http_target_id_4 = "${length(split(",", var.target_ids)) >= 4 ? "${local.http_tg_attachment_conditionals}" :0}" + http_target_id_5 = "${length(split(",", var.target_ids)) >= 5 ? "${local.http_tg_attachment_conditionals}" :0}" + http_target_id_6 = "${length(split(",", var.target_ids)) >= 6 ? "${local.http_tg_attachment_conditionals}" :0}" + http_target_id_7 = "${length(split(",", var.target_ids)) >= 7 ? "${local.http_tg_attachment_conditionals}" :0}" + http_target_id_8 = "${length(split(",", var.target_ids)) >= 8 ? "${local.http_tg_attachment_conditionals}" :0}" # HTTPS target group attachment - https_target_id_1 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 1 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - https_target_id_2 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 2 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - https_target_id_3 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 3 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - https_target_id_4 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 4 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - https_target_id_5 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 5 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - https_target_id_6 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 6 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - https_target_id_7 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 7 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" - https_target_id_8 = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(split(",", var.target_ids)) >= 8 ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" :0}" + https_tg_attachment_conditionals = "${var.lb_https_listener ? "${!var.lb_https_offloading ? "${length(var.https_target_group_names) == "${length(var.https_target_group_ports)}" ? "${length(var.https_target_group_names)}" : 0}" :0}" :0}" + https_target_id_1 = "${length(split(",", var.target_ids)) >= 1 ? "${local.https_tg_attachment_conditionals}" :0}" + https_target_id_2 = "${length(split(",", var.target_ids)) >= 2 ? "${local.https_tg_attachment_conditionals}" :0}" + https_target_id_3 = "${length(split(",", var.target_ids)) >= 3 ? "${local.https_tg_attachment_conditionals}" :0}" + https_target_id_4 = "${length(split(",", var.target_ids)) >= 4 ? "${local.https_tg_attachment_conditionals}" :0}" + https_target_id_5 = "${length(split(",", var.target_ids)) >= 5 ? "${local.https_tg_attachment_conditionals}" :0}" + https_target_id_6 = "${length(split(",", var.target_ids)) >= 6 ? "${local.https_tg_attachment_conditionals}" :0}" + https_target_id_7 = "${length(split(",", var.target_ids)) >= 7 ? "${local.https_tg_attachment_conditionals}" :0}" + https_target_id_8 = "${length(split(",", var.target_ids)) >= 8 ? "${local.https_tg_attachment_conditionals}" :0}" }