terraform-deploy-wordpress-site / instance-LB.tf
instance-LB.tf
Raw
resource "aws_lb" "server_lb" {
  name               = "server-lb"
  internal           = false
  load_balancer_type = "application"
  security_groups    = [aws_security_group.elb_sg.id]

  subnets = [
    aws_subnet.elb_subnetA.id,
    aws_subnet.elb_subnetB.id
  ]
}

resource "aws_lb_target_group" "serverTG" {
  name     = "serverTG"
  port     = 80
  protocol = "HTTP"
  vpc_id   = aws_vpc.wp_vpc.id

  health_check {
    enabled             = true
    port                = 80
    protocol            = "HTTP"
    path                = "/"
    matcher             = "200"
    healthy_threshold   = 3
    unhealthy_threshold = 3
  }
}

resource "aws_lb_listener" "serverListener" {
  load_balancer_arn = aws_lb.server_lb.arn
  port              = "80"
  protocol          = "HTTP"

  default_action {
    type             = "forward"
    target_group_arn = aws_lb_target_group.serverTG.arn
  }
}