将多个EC2实例附加到“ aws_alb_target_group_attachment”中

时间:2020-03-07 15:11:24

标签: terraform-provider-aws

我正在尝试将多个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时,我不知道执行此操作的最佳方法是什么

0 个答案:

没有答案