This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
locals { | |
target_groups_count = 2 | |
target_groups = "${list( | |
map("name", "foo", | |
"backend_protocol", "HTTP", | |
"backend_port", 80, | |
), | |
map("name", "bar", | |
"backend_protocol", "HTTP", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "target_groups" { | |
description = "A list of maps containing key/value pairs that define the target groups to be created. Order of these maps is important and the index of these are to be referenced in listener definitions. Required key/values: name, backend_protocol, backend_port. Optional key/values are in the target_groups_defaults variable." | |
type = "list" | |
default = [] | |
} | |
variable "target_groups_count" { | |
description = "A manually provided count/length of the target_groups list of maps since the list cannot be computed." | |
default = 0 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_lb_target_group" "main" { | |
name = "${lookup(var.target_groups[count.index], "name")}" | |
vpc_id = "${var.vpc_id}" | |
port = "${lookup(var.target_groups[count.index], "backend_port")}" | |
protocol = "${upper(lookup(var.target_groups[count.index], "backend_protocol"))}" | |
deregistration_delay = "${lookup(var.target_groups[count.index], "deregistration_delay", lookup(var.target_groups_defaults, "deregistration_delay"))}" | |
target_type = "${lookup(var.target_groups[count.index], "target_type", lookup(var.target_groups_defaults, "target_type"))}" | |
health_check { | |
interval = "${lookup(var.target_groups[count.index], "health_check_interval", lookup(var.target_groups_defaults, "health_check_interval"))}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resource "aws_lb_target_group" "main" { | |
name = "${lookup(var.target_groups[count.index], "name")}" | |
vpc_id = "${var.vpc_id}" | |
port = "${lookup(var.target_groups[count.index], "backend_port")}" | |
protocol = "${upper(lookup(var.target_groups[count.index], "backend_protocol"))}" | |
deregistration_delay = "${lookup(var.target_groups[count.index], "deregistration_delay", lookup(var.target_groups_defaults, "deregistration_delay"))}" | |
target_type = "${lookup(var.target_groups[count.index], "target_type", lookup(var.target_groups_defaults, "target_type"))}" | |
health_check { | |
interval = "${lookup(var.target_groups[count.index], "health_check_interval", lookup(var.target_groups_defaults, "health_check_interval"))}" |