Hi,
I am trying to create ALB and Web Servers by using modules. While Web Servers and ALB gets created, I am unable to add the web servers as targets to the target group. The first one gets attached while the 2nd one fails.
Error: Error registering targets with target group: ValidationError: Instance ID ' i-0cf0a85c8866214ca' is not valid
status code: 400, request id: 208778c2-c939-4ee5-a134-1434d1132903
Below are my code snippets:
load_balancer\main.tf
.
.
resource "aws_alb_target_group_attachment" "tg_attach" {
count = var.tg
target_group_arn = aws_alb_target_group.front_end_tg.arn
port = 80
target_id = element(split(",", var.web_server_id), count.index)
}
web-servers\output.tf
output "web_server_id" {
value = join(", ", aws_instance.web.*.id)
}
root\main.tf
#Deploy Application Load Balancer
module "load_balancer" {
source = "./load_balancer"
alb_depends_on = [module.web_servers]
pubsubnets = module.networking.public_subnets
alb_source = module.networking.alb_source
alb_perf = module.networking.alb_perf
web_server_id = module.web_servers.web_server_id
perf_vpc = module.networking.vpc_id
tg = var.web_count
}
root\terraform.tfvars
web_count = 2
Could anyone please advise how do I make the error go away?
AWS Console