I get the following error at the end of the output.
Error: Error registering targets with target group: ValidationError: Instance ID ‘arn:aws:elasticloadbalancing:us-west-2:993276023740:targetgroup/ilab-app-loadbalancer/52c7cb8bc3d39e61’ is not valid
status code: 400, request id: abedd3c2-d905-4af4-9a32-c1e30a9e4e1dwith aws_lb_target_group_attachment.ilab_tg_attach,
on resilience.tf line 48, in resource "aws_lb_target_group_attachment" "ilab_tg_attach":
48: resource "aws_lb_target_group_attachment" "ilab_tg_attach" {
Here is the code I am using in terraform:
Note: Funny thing is that it creates the targetgroup attachments and it works, it adds two hosts.
resource "aws_lb_target_group_attachment" "ilab_tg_attach" {
target_id = aws_lb_target_group.ilab_alb.id
target_group_arn = aws_lb_target_group.ilab_alb.arn
port = 80
}
resource "aws_autoscaling_group" "ilab_asg" {
name = "ilab_asg"
vpc_zone_identifier = ["${aws_subnet.ilab_subnet_pub_a.id}", "${aws_subnet.ilab_subnet_pub_b.id}"]
launch_configuration = aws_launch_configuration.ilab_lt.name
min_size = 2
max_size = 2
health_check_grace_period = 300
health_check_type = "ELB"
force_delete = true
target_group_arns = [aws_lb_target_group.ilab_alb.arn]
tag {
key = "Name"
value = "EC2 Instance"
propagate_at_launch = true
}
}
2
Answers
Thanks all for the help. For anyone else trying to get this working properly here is the full code for my alb/asg.
You get a validation error because
target_id
should be the ID of the target your are trying to register, not the target group itself.From the terraform documentation:
The reason why it registers two targets is that the autoscaling group actually tries to do its job by creating two EC2 instances (
min_size = 2
). Since you are using an ASG, you probably would want to get rid of theaws_lb_target_group_attachment
all together.