使用Terraform将AWS实例添加到目标组和ALB的问题

时间:2020-03-10 11:03:32

标签: amazon-web-services aws-load-balancer aws-elb

我正在尝试创建具有2个目标组的应用程序负载平衡器。实例位于公共子网中。使用以下代码,我能够创建资源,但实例未附加目标组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: 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.

我尝试如下更改target_id,但还是没有运气。

target_id = "${element(var.no-of-frontend-attachments.*.id, count.index)}"

请帮助我了解此问题

0 个答案:

没有答案