Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform error This value does not have any indices

Tags:

terraform

I am in the process of upgrading from tf 11 to tf 12 and I just ran into this issue. This used to work in tf 11 and is now broken in tf 12. Can someone help me figure out the issue?

data "aws_subnet_ids" "private" {
  vpc_id = data.aws_ssm_parameter.vpc_id.value

  tags = {
    tier = "private"
  }
}

data "aws_subnet" "private" {
  count = length(data.aws_subnet_ids.private.ids)
  id    = data.aws_subnet_ids.private.ids[count.index]
}
27:   id    = data.aws_subnet_ids.private.ids[count.index]
    |----------------
    | count.index is 0
    | data.aws_subnet_ids.private.ids is set of string with 3 elements

This value does not have any indices.
like image 643
Evan Gertis Avatar asked Nov 02 '25 03:11

Evan Gertis


1 Answers

This fixed it

data "aws_subnet" "private" {
  for_each = data.aws_subnet_ids.private.ids
  id    = each.value
}
like image 127
Evan Gertis Avatar answered Nov 04 '25 04:11

Evan Gertis