Reputation: 51
I am trying to write code for existing EC2 Instances in aws_lb_target_group_attachment and I get unsupported block type. Here is the code:
variable "target_id" {
default = [
{
name = "i-123456789abcdefgh"
},
{
name = "i-24680bcgdhkij1234"
}
]
}
resource "aws_lb_target_group_attachment" "mytestAlb" {
target_group_arn = aws_lb_target_group.mytestAlb.arn
dynamic "target_id" {
for_each = var.target_id
content {
name = target_id.value["name"]
}
}
}
I get two errors
Upvotes: 1
Views: 316
Reputation: 238131
This happens, because target_id
is not a block. Its requires a single instance id.
Thus, you should be doing:
resource "aws_lb_target_group_attachment" "mytestAlb" {
for_each = {for idx, v in var.target_id: idx => v}
target_group_arn = aws_lb_target_group.mytestAlb.arn
target_id = each.value["name"]
}
Upvotes: 1