-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalb.tf
51 lines (45 loc) · 1.33 KB
/
alb.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
resource "random_string" "random_prefix" {
length = 5
special = false
upper = false
}
# Create a application load balancer for etcd
resource "aws_lb" "alb" {
name = "${random_string.random_prefix.result}-alb"
load_balancer_type = "application"
security_groups = [aws_security_group.etcd.id]
subnets = local.subnet_ids_list
internal = false
}
# Create the target group for the ALB
resource "aws_lb_target_group" "group" {
name = "${random_string.random_prefix.result}-alb"
port = "2379"
protocol = "HTTP"
vpc_id = var.vpc_id
health_check {
healthy_threshold = 3
unhealthy_threshold = 10
timeout = 5
interval = 10
path = "/version"
port = "2379"
}
}
# Create a listener on the default ETCD listener port
resource "aws_lb_listener" "listener_http" {
load_balancer_arn = aws_lb.alb.arn
port = "2379"
protocol = "HTTP"
default_action {
target_group_arn = aws_lb_target_group.group.arn
type = "forward"
}
}
# Target our EC2s
resource "aws_lb_target_group_attachment" "etcds" {
count = var.node_count
target_group_arn = aws_lb_target_group.group.arn
target_id = aws_instance.etcds[count.index].id
port = 2379
}