I've built an AWS ALB & Target group via Terraform and everything looks correct but the Target Group is reporting unhealthy for HTTP, HTTPS, and TCP. The instance is a t3.nano in us-east-2 and has Nginx installed and running.
I've verified the following:
- Nginx is configured and running on ports 80 & 443
- Security groups allow HTTP & HTTPS from 0.0.0.0/0
- Instance is on a public subnet (that is, the 0.0.0.0/0 route is to the IGW)
If I access the instance's public IP from Internet, and the "Welcome to nginx!" page is displayed. This request shows up both in /var/log/nginx/access.log. tcpdump port 80 shows requests coming from Internet but nothing indicating an AWS healthcheck.
I've used ALBs and Target groups before and never encountered an issue like this. The only difference is this instance was created with Terraform.
I think you need to configure the
target_type
parameter in yourlb_target_group
resource. The default value isinstance
, that configuration requires useautoscaling_group
for EC2 instances. If you useaws_instance
for EC2, you need useip
parameter.https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group#target_type