I am trying to create a application load balancer with 2 Target groups. The instances are in public subnet. with the below code I am able to create the resources but instances are not attaching the target group a
albmod.tf
no-of-frontend-attachments = "${module.ec2-app-v1.aws-instance}"
var.tf
variable "no-of-frontend-attachments" {
type = "list"
}
alb.tf
resource "aws_alb_target_group_attachment" "frontend-attachments" {
count = "${length(concat(var.no-of-frontend-attachments))}"
target_group_arn = "${aws_lb_target_group.frontend-target-group.arn}"
target_id = "${element(var.no-of-frontend-attachments,count.index )}"
}
ERROR
Error: Incorrect attribute value type
on modules/alb/alb.tf line 54, in resource "aws_alb_target_group_attachment" "frontend-attachments":
54: target_id = "${element(var.no-of-frontend-attachments,count.index )}"
|----------------
| count.index is 0
| var.no-of-frontend-attachments is tuple with 1 element
Inappropriate value for attribute "target_id": string required.
I tried to change the target_id as below but still no luck.
target_id = "${element(var.no-of-frontend-attachments.*.id, count.index)}"
Please help me to understand this issue