Hello, I’m new at Terraform and loving it… Except when I get stuck and can’t find answers.
So I have a problem where my targets are coming up unhealthy. I see the talents and skills of many but for now I’m just trying to get a handle on the basics. Everything else works but the Target is coming up unhealthy in the target group. However, it’s showing quite healthy as an instance.
Thanks all.
alb.tf:
#Application LoadBalancer
resource “aws_lb” “test” {
name = “test-lb-tf”
internal = false
load_balancer_type = “application”
subnets = ["{aws_subnet.subnet1.id}" , "{aws_subnet.subnet2.id}"]
enable_deletion_protection = false
tags = {
Environment = “production”
}
}
#Target Group
resource “aws_lb_target_group” “test-tg” {
name = “tf-example-lb-tg”
port = 80
protocol = “HTTP”
vpc_id = aws_vpc.main.id
health_check {
path = “/”
port = 80
protocol = “HTTP”
healthy_threshold = 5
unhealthy_threshold = 5
interval = 30
timeout = 5
}
}
#Target group attachment
resource “aws_lb_target_group_attachment” “test-attach” {
target_group_arn = aws_lb_target_group.test-tg.arn
target_id = aws_instance.web.id
port = 80
}
Listener
resource “aws_lb_listener” “front_end” {
load_balancer_arn = aws_lb.test.arn
port = “80”
protocol = “HTTP”
default_action {
type = “forward”
target_group_arn = aws_lb_target_group.test-tg.arn
}
}