Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

453
Views
Error aws_alb_target_group has "count" set, its attributes must be accessed on specific instances

I am using Terraform v0.12.26 and set up and aws_alb_target_group as:

resource "aws_alb_target_group" "my-group" {
  count = "${length(local.target_groups)}"
  name = "${var.namespace}-my-group-${
    element(local.target_groups, count.index)
  }"

  port     = 8081
  protocol = "HTTP"
  vpc_id   = var.vpc_id

  health_check {
    healthy_threshold   = var.health_check_healthy_threshold
    unhealthy_threshold = var.health_check_unhealthy_threshold
    timeout             = var.health_check_timeout
    interval            = var.health_check_interval
    path                = var.path
  }

  tags = {
    Name = var.namespace
  }

  lifecycle {
    create_before_destroy = true
  }
}

The locals look like:

locals {
  target_groups = [
    "green",
    "blue",
  ]
}

When I run terraform apply it returns the following error:

Error: Missing resource instance key

  on ../../modules/aws_alb/outputs.tf line 3, in output "target_groups_arn":
   3:     aws_alb_target_group.http.arn,

Because aws_alb_target_group.http has "count" set, its attributes must be
accessed on specific instances.

For example, to correlate with indices of a referring resource, use:
    aws_alb_target_group.http[count.index]

I followed this implementation

Any idea how to fix it?

Output

output "target_groups_arn" {
  value = [
    aws_alb_target_group.http.arn,
  ]
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Since aws_alb_target_group.http is a counted resource you'll need to reference specific instances by index or all of them as a list with [*] (aka Splat Expressions) as follows:

output "target_groups_arn" {
  value = aws_alb_target_group.http[*].arn,
}

The target_groups_arn output will be a list of the TG ARNs.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!