我正在尝试将多个ec2 ID引用到“ aws_alb_target_group_attachment”中的target_id
中,但是我不确定哪种方法正确。
我的模块:
resource "aws_alb_target_group_attachment" "attach_webserver" {
count = 8
target_group_arn = aws_alb_target_group.webserver_target_group.arn
target_id = "${element(split(",", join(",", var.instance_id_subnet_1, var.instance_id_subnet_2, var.instance_id_subnet_3, var.instance_id_subnet_4)), count.index)}"
port = 80
}
我有count = 8
,因为每个变量都有2个实例ID。
但是我得到了:
on modules/alb/main.tf line 54, in resource "aws_alb_target_group_attachment" "attach_webserver":
54: target_id = "${element(split(",", join(",", var.instance_id_subnet_1, var.instance_id_subnet_2, var.instance_id_subnet_3, var.instance_id_subnet_4)), count.index)}"
|----------------
| var.instance_id_subnet_4 is tuple with 1 element
Invalid value for "lists" parameter: element 0: string required.
我搜索了很多地方,当我们有多个实例ID时,我不知道执行此操作的最佳方法是什么