-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalb.tf
45 lines (38 loc) · 1.23 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
# https://registry.terraform.io/modules/terraform-aws-modules/alb
module "alb" {
source = "terraform-aws-modules/alb/aws"
name = "alb"
enable_cross_zone_load_balancing = true
load_balancer_type = "application"
vpc_id = module.vpc.vpc_id
subnets = tolist(module.vpc.public_subnets)
security_groups = [module.lb_sg.this_security_group_id]
http_tcp_listeners = [
{
port = 80
protocol = "HTTP"
target_group_index = 0
action_type = "forward"
}
]
target_groups = [
{
name_prefix = "alb-"
backend_protocol = "HTTP"
backend_port = 80
target_type = "instance"
}
]
tags = {
Environment = "dev"
Terraform = "true"
}
}
resource "aws_autoscaling_attachment" "asg1-alb-listener-tg" {
autoscaling_group_name = module.asg1.this_autoscaling_group_id
alb_target_group_arn = tolist(module.alb.target_group_arns)[0]
}
resource "aws_autoscaling_attachment" "asg2-alb-listener-tg" {
autoscaling_group_name = module.asg2.this_autoscaling_group_id
alb_target_group_arn = tolist(module.alb.target_group_arns)[0]
}