forked from techservicesillinois/terraform-aws-ecs-service
-
Notifications
You must be signed in to change notification settings - Fork 1
/
target_group.tf
47 lines (40 loc) · 1.83 KB
/
target_group.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service-load-balancing.html
# TODO : It is possible to attach additional containers on different
# ports using aws_lb_target_group_attachment
# https://www.terraform.io/docs/providers/aws/r/lb_target_group_attachment.html
# Should we support this?
resource "aws_lb_target_group" "default" {
count = length(var.load_balancer) > 0 ? 1 : 0
name = var.name
port = local.container_port
# Valid vales for protocol are HTTP/HTTPS. We only support HTTP
# because we trust the path between the load balancer and the
# containers. If not then do NOT use a load balancer.
protocol = "HTTP"
vpc_id = local.lb_vpc_id
deregistration_delay = local.deregistration_delay
dynamic "stickiness" {
for_each = [var.stickiness]
content {
cookie_duration = lookup(stickiness.value, "cookie_duration", null)
enabled = lookup(stickiness.value, "enabled", null)
type = stickiness.value.type
}
}
dynamic "health_check" {
for_each = [var.health_check]
content {
enabled = lookup(health_check.value, "enabled", null)
healthy_threshold = lookup(health_check.value, "healthy_threshold", null)
interval = lookup(health_check.value, "interval", null)
matcher = lookup(health_check.value, "matcher", null)
path = lookup(health_check.value, "path", null)
port = lookup(health_check.value, "port", null)
protocol = lookup(health_check.value, "protocol", null)
timeout = lookup(health_check.value, "timeout", null)
unhealthy_threshold = lookup(health_check.value, "unhealthy_threshold", null)
}
}
target_type = local.network_mode == "awsvpc" ? "ip" : "instance"
tags = merge({ "Name" = var.name }, var.tags)
}