-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnlb.tf
65 lines (54 loc) · 1.46 KB
/
nlb.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
resource "aws_lb" "ecs" {
load_balancer_type = "network"
internal = false
name = "ecs-${var.name}"
subnets = var.public_subnet_ids
security_groups = length(var.nlb_security_group_ids) > 0 ? var.nlb_security_group_ids : [aws_security_group.nlb.id]
idle_timeout = 400
dynamic "access_logs" {
for_each = compact([var.lb_access_logs_bucket])
content {
bucket = var.lb_access_logs_bucket
prefix = var.lb_access_logs_prefix
enabled = true
}
}
tags = {
Name = "ecs-${var.name}"
}
}
resource "aws_lb_listener" "ecs_default" {
load_balancer_arn = aws_lb.ecs.arn
port = "1194"
protocol = "TCP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.ecs_default.arn
}
}
# Generate a random string to add it to the name of the Target Group
resource "random_string" "alb_prefix" {
length = 4
upper = false
special = false
}
resource "aws_lb_target_group" "ecs_default" {
name = substr("ecs-${var.name}-${random_string.alb_prefix.result}", 0, 32)
port = 1194
protocol = "TCP"
vpc_id = var.vpc_id
deregistration_delay = 10
target_type = "instance"
health_check {
protocol = "TCP"
port = 1194
interval = 30
}
stickiness {
enabled = false
type = "source_ip"
}
lifecycle {
create_before_destroy = true
}
}