-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelb.tf
More file actions
51 lines (44 loc) · 1.13 KB
/
elb.tf
File metadata and controls
51 lines (44 loc) · 1.13 KB
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
# ./elb.tf
# ALB
resource "aws_lb" "my_alb" {
name = "${var.ec2_instance_name}-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb_sg.id]
subnets = [
aws_subnet.public_subnets[0].id,
aws_subnet.public_subnets[1].id
]
enable_deletion_protection = false
tags = {
Name = "${var.ec2_instance_name}-alb"
}
}
# ALBのターゲットグループ
resource "aws_lb_target_group" "my_target_group" {
name = "${var.ec2_instance_name}-target-group"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.vpc03.id
health_check {
path = "/"
interval = 30
timeout = 5
healthy_threshold = 5
unhealthy_threshold = 2
matcher = "200"
}
tags = {
Name = "${var.ec2_instance_name}-target-group"
}
}
# ALBのリスナー
resource "aws_lb_listener" "my_listener" {
load_balancer_arn = aws_lb.my_alb.arn
port = 80
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.my_target_group.arn
}
}