Terraform get a list of IDs from a resource created with count

Viewed 8328

I'm defining a number of subnet resources:

resource "aws_subnet" "my_subnets" {
  count = 8
  cidr_block = cidrsubnet(var.cidr_block, 3, count.index)
  vpc_id = var.vpc
}

I then have to pass a list of those subnet IDs to another resource. I know that the IDs are reachable on aws_subnet.my_subnets[count].id, but how do I loop through those and append all of the values to a list in order to pass it to the other resource? The recommendation I've seen is to tag the subnets, then use a data attribute to look up those subnets, and they will be returned in a list format, but I have the IDs right there on the output of the resource.

1 Answers
Related