Skip to content

Commit

Permalink
feat: add resource application load balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
dusdjhyeon committed Dec 4, 2023
1 parent ac6c9f7 commit c1ccdbe
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions module-ec2/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,41 @@ resource "aws_autoscaling_group" "khu-asg" {
min_size = 2
max_size = 5
}

# load balancer
resource "aws_lb" "khu-alb" {
name = "khu-alb"
internal = false
load_balancer_type = "application"

security_groups = [aws_security_group.alb-sg.id]
subnets = var.private_subnet_ids

tags = {
Name = "${var.env_name}-alb"
}
}

resource "aws_lb_listener" "khu-alb-listner" {
load_balancer_arn = aws_lb.khu-alb.arn
port = 80
protocol = "HTTP"

default_action {
type = "forward"
target_group_arn = aws_lb_target_group.khu-alb-tg.arn
}
}

resource "aws_lb_target_group" "khu-alb-tg" {
name = "khu-alb-tg"
port = 8000
protocol = "HTTP"
vpc_id = var.vpc_id
}

resource "aws_lb_target_group_attachment" "khu-tg-attach" {
target_group_arn = aws_lb_target_group.khu-alb-tg.arn
target_id = aws_autoscaling_group.khu-asg.id
port = 8000
}

0 comments on commit c1ccdbe

Please sign in to comment.