-
Notifications
You must be signed in to change notification settings - Fork 0
/
alb.tf
50 lines (40 loc) · 1.48 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
resource "aws_lb" "wordpress_alb" {
name = "wordpress-alb"
internal = false # Set to true if the ALB should be internal
load_balancer_type = "application"
subnets = [aws_subnet.public[0].id, aws_subnet.public[1].id] # Specify your public subnet(s) here
security_groups = [aws_security_group.wordpress_sg.id]
enable_deletion_protection = false # Set to true to prevent accidental deletion
tags = {
Name = "wordpress_alb ${var.tagNameDate}"
}
}
resource "aws_lb_target_group" "Wordpress_target_group" {
name = "wordpress-target-group"
port = 80
protocol = "HTTP"
vpc_id = aws_vpc.vpc.id
target_type = "instance"
# Add tags
tags = {
Name = "wordpress-target-group ${var.tagNameDate}"
}
}
resource "aws_lb_target_group_attachment" "wordpress_target_group_attachment" {
target_group_arn = aws_lb_target_group.Wordpress_target_group.arn
target_id = aws_instance.wordpress_instance.id
port = 80
}
resource "aws_autoscaling_attachment" "name" {
autoscaling_group_name = aws_autoscaling_group.wordpress_autoscaling_group.id
lb_target_group_arn = aws_lb_target_group.Wordpress_target_group.arn
}
resource "aws_lb_listener" "wordpress_listener" {
load_balancer_arn = aws_lb.wordpress_alb.arn
port = "80"
protocol = "HTTP"
default_action {
type = "forward"
target_group_arn = aws_lb_target_group.Wordpress_target_group.arn
}
}