terraform-aws-modules/terraform-aws-alb

Bug in resource "aws_lb_target_group_attachment", main.tf, raw 533

Michaelcode2 opened this issue · 4 comments

Description

Generation of the load balancer fails.

│ Error: Unsupported attribute
│   on /tmp/terraform-data/modules/terraform-aws-alb/main.tf line 537, in resource "aws_lb_target_group_attachment" "this":
│  537:   target_id         = each.value.target_id
│     │ each.value is object with 5 attributes
│ This object does not have an attribute named "target_id".

Resource with issue:

resource "aws_lb_target_group_attachment" "this" {
  for_each = { for k, v in var.target_groups : k => v if local.create && lookup(v, "create_attachment", true) }

  target_group_arn  = aws_lb_target_group.this[each.key].arn
  target_id         = each.value.target_id
  port              = try(each.value.target_type, null) == "lambda" ? null : try(each.value.port, var.default_port)
  availability_zone = try(each.value.availability_zone, null)

  depends_on = [aws_lambda_permission.this]
}

Discovery:

lookup(v, "create_attachment", true) is wrong here

lookup(v, "create_attachment", true) ensures that the resource is created if the create_attachment key in the current target group configuration is either true or not present (defaulting to true)

By default this variable is not present and function understands this as value "true" and tries to generate aws_lb_target_group_attachment when it is not configured

Slava Ukraini ! Glory to Ukraine! Героям слава!

Thanks for explanation!

This could be mentioned in the readme. It will be very useful.

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.