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

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 Answer

Found what I was thinking of - splat expression:

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like