Skip to content

Commit d400c45

Browse files
Merge pull request #81 from alkalinecoffee/master
Merge target_groups_defaults
2 parents 7451e34 + fa2f74b commit d400c45

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

alb_no_logs.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ resource "aws_lb_target_group" "main_no_logs" {
2525
vpc_id = "${var.vpc_id}"
2626
port = "${lookup(var.target_groups[count.index], "backend_port")}"
2727
protocol = "${upper(lookup(var.target_groups[count.index], "backend_protocol"))}"
28-
deregistration_delay = "${lookup(var.target_groups[count.index], "deregistration_delay", lookup(var.target_groups_defaults, "deregistration_delay"))}"
29-
target_type = "${lookup(var.target_groups[count.index], "target_type", lookup(var.target_groups_defaults, "target_type"))}"
28+
deregistration_delay = "${lookup(var.target_groups[count.index], "deregistration_delay", lookup(local.target_groups_defaults, "deregistration_delay"))}"
29+
target_type = "${lookup(var.target_groups[count.index], "target_type", lookup(local.target_groups_defaults, "target_type"))}"
3030

3131
health_check {
32-
interval = "${lookup(var.target_groups[count.index], "health_check_interval", lookup(var.target_groups_defaults, "health_check_interval"))}"
33-
path = "${lookup(var.target_groups[count.index], "health_check_path", lookup(var.target_groups_defaults, "health_check_path"))}"
34-
port = "${lookup(var.target_groups[count.index], "health_check_port", lookup(var.target_groups_defaults, "health_check_port"))}"
35-
healthy_threshold = "${lookup(var.target_groups[count.index], "health_check_healthy_threshold", lookup(var.target_groups_defaults, "health_check_healthy_threshold"))}"
36-
unhealthy_threshold = "${lookup(var.target_groups[count.index], "health_check_unhealthy_threshold", lookup(var.target_groups_defaults, "health_check_unhealthy_threshold"))}"
37-
timeout = "${lookup(var.target_groups[count.index], "health_check_timeout", lookup(var.target_groups_defaults, "health_check_timeout"))}"
32+
interval = "${lookup(var.target_groups[count.index], "health_check_interval", lookup(local.target_groups_defaults, "health_check_interval"))}"
33+
path = "${lookup(var.target_groups[count.index], "health_check_path", lookup(local.target_groups_defaults, "health_check_path"))}"
34+
port = "${lookup(var.target_groups[count.index], "health_check_port", lookup(local.target_groups_defaults, "health_check_port"))}"
35+
healthy_threshold = "${lookup(var.target_groups[count.index], "health_check_healthy_threshold", lookup(local.target_groups_defaults, "health_check_healthy_threshold"))}"
36+
unhealthy_threshold = "${lookup(var.target_groups[count.index], "health_check_unhealthy_threshold", lookup(local.target_groups_defaults, "health_check_unhealthy_threshold"))}"
37+
timeout = "${lookup(var.target_groups[count.index], "health_check_timeout", lookup(local.target_groups_defaults, "health_check_timeout"))}"
3838
protocol = "${upper(lookup(var.target_groups[count.index], "healthcheck_protocol", lookup(var.target_groups[count.index], "backend_protocol")))}"
39-
matcher = "${lookup(var.target_groups[count.index], "health_check_matcher", lookup(var.target_groups_defaults, "health_check_matcher"))}"
39+
matcher = "${lookup(var.target_groups[count.index], "health_check_matcher", lookup(local.target_groups_defaults, "health_check_matcher"))}"
4040
}
4141

4242
stickiness {
4343
type = "lb_cookie"
44-
cookie_duration = "${lookup(var.target_groups[count.index], "cookie_duration", lookup(var.target_groups_defaults, "cookie_duration"))}"
45-
enabled = "${lookup(var.target_groups[count.index], "stickiness_enabled", lookup(var.target_groups_defaults, "stickiness_enabled"))}"
44+
cookie_duration = "${lookup(var.target_groups[count.index], "cookie_duration", lookup(local.target_groups_defaults, "cookie_duration"))}"
45+
enabled = "${lookup(var.target_groups[count.index], "stickiness_enabled", lookup(local.target_groups_defaults, "stickiness_enabled"))}"
4646
}
4747

4848
tags = "${merge(var.tags, map("Name", lookup(var.target_groups[count.index], "name")))}"

alb_w_logs.tf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ resource "aws_lb_target_group" "main" {
3131
vpc_id = "${var.vpc_id}"
3232
port = "${lookup(var.target_groups[count.index], "backend_port")}"
3333
protocol = "${upper(lookup(var.target_groups[count.index], "backend_protocol"))}"
34-
deregistration_delay = "${lookup(var.target_groups[count.index], "deregistration_delay", lookup(var.target_groups_defaults, "deregistration_delay"))}"
35-
target_type = "${lookup(var.target_groups[count.index], "target_type", lookup(var.target_groups_defaults, "target_type"))}"
34+
deregistration_delay = "${lookup(var.target_groups[count.index], "deregistration_delay", lookup(local.target_groups_defaults, "deregistration_delay"))}"
35+
target_type = "${lookup(var.target_groups[count.index], "target_type", lookup(local.target_groups_defaults, "target_type"))}"
3636

3737
health_check {
38-
interval = "${lookup(var.target_groups[count.index], "health_check_interval", lookup(var.target_groups_defaults, "health_check_interval"))}"
39-
path = "${lookup(var.target_groups[count.index], "health_check_path", lookup(var.target_groups_defaults, "health_check_path"))}"
40-
port = "${lookup(var.target_groups[count.index], "health_check_port", lookup(var.target_groups_defaults, "health_check_port"))}"
41-
healthy_threshold = "${lookup(var.target_groups[count.index], "health_check_healthy_threshold", lookup(var.target_groups_defaults, "health_check_healthy_threshold"))}"
42-
unhealthy_threshold = "${lookup(var.target_groups[count.index], "health_check_unhealthy_threshold", lookup(var.target_groups_defaults, "health_check_unhealthy_threshold"))}"
43-
timeout = "${lookup(var.target_groups[count.index], "health_check_timeout", lookup(var.target_groups_defaults, "health_check_timeout"))}"
38+
interval = "${lookup(var.target_groups[count.index], "health_check_interval", lookup(local.target_groups_defaults, "health_check_interval"))}"
39+
path = "${lookup(var.target_groups[count.index], "health_check_path", lookup(local.target_groups_defaults, "health_check_path"))}"
40+
port = "${lookup(var.target_groups[count.index], "health_check_port", lookup(local.target_groups_defaults, "health_check_port"))}"
41+
healthy_threshold = "${lookup(var.target_groups[count.index], "health_check_healthy_threshold", lookup(local.target_groups_defaults, "health_check_healthy_threshold"))}"
42+
unhealthy_threshold = "${lookup(var.target_groups[count.index], "health_check_unhealthy_threshold", lookup(local.target_groups_defaults, "health_check_unhealthy_threshold"))}"
43+
timeout = "${lookup(var.target_groups[count.index], "health_check_timeout", lookup(local.target_groups_defaults, "health_check_timeout"))}"
4444
protocol = "${upper(lookup(var.target_groups[count.index], "healthcheck_protocol", lookup(var.target_groups[count.index], "backend_protocol")))}"
45-
matcher = "${lookup(var.target_groups[count.index], "health_check_matcher", lookup(var.target_groups_defaults, "health_check_matcher"))}"
45+
matcher = "${lookup(var.target_groups[count.index], "health_check_matcher", lookup(local.target_groups_defaults, "health_check_matcher"))}"
4646
}
4747

4848
stickiness {
4949
type = "lb_cookie"
50-
cookie_duration = "${lookup(var.target_groups[count.index], "cookie_duration", lookup(var.target_groups_defaults, "cookie_duration"))}"
51-
enabled = "${lookup(var.target_groups[count.index], "stickiness_enabled", lookup(var.target_groups_defaults, "stickiness_enabled"))}"
50+
cookie_duration = "${lookup(var.target_groups[count.index], "cookie_duration", lookup(local.target_groups_defaults, "cookie_duration"))}"
51+
enabled = "${lookup(var.target_groups[count.index], "stickiness_enabled", lookup(local.target_groups_defaults, "stickiness_enabled"))}"
5252
}
5353

5454
tags = "${merge(var.tags, map("Name", lookup(var.target_groups[count.index], "name")))}"

locals.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
locals {
2+
target_groups_default_configs = {
3+
cookie_duration = 86400
4+
deregistration_delay = 300
5+
health_check_interval = 10
6+
health_check_healthy_threshold = 3
7+
health_check_path = "/"
8+
health_check_port = "traffic-port"
9+
health_check_timeout = 5
10+
health_check_unhealthy_threshold = 3
11+
health_check_matcher = "200-299"
12+
stickiness_enabled = true
13+
target_type = "instance"
14+
}
15+
16+
target_groups_defaults = "${merge(local.target_groups_default_configs, var.target_groups_defaults)}"
17+
}

variables.tf

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,7 @@ variable "target_groups_count" {
128128

129129
variable "target_groups_defaults" {
130130
description = "Default values for target groups as defined by the list of maps."
131-
type = "map"
132-
133-
default = {
134-
"cookie_duration" = 86400
135-
"deregistration_delay" = 300
136-
"health_check_interval" = 10
137-
"health_check_healthy_threshold" = 3
138-
"health_check_path" = "/"
139-
"health_check_port" = "traffic-port"
140-
"health_check_timeout" = 5
141-
"health_check_unhealthy_threshold" = 3
142-
"health_check_matcher" = "200-299"
143-
"stickiness_enabled" = true
144-
"target_type" = "instance"
145-
}
131+
default = {}
146132
}
147133

148134
variable "vpc_id" {

0 commit comments

Comments
 (0)