Combining "For_each" into a list of generated resources

Hey guys,

I’m using “for_each” syntax to generate a X stacks of resources for a particular project. In particular, I’m generating X aws_capacity_provider objects, 1 for each stack.

resource "aws_ecs_capacity_provider" "my_capacity_provider" {
  for_each = local.services

  name = each.key
   ....other stuff....
}

However, I now want to add all these generated capacity providers to a single cluster, using the following type of syntax:

data "aws_ecs_cluster" "my_ecs_cluster" {
  cluster_name = local.ecs_cluster_name
  capacity_providers = [PSEUDOCODE: for_each generated aws_ecs_capacity_provider, add to this list]
}

Anybody know the proper syntax for this? I’m relatively new to Terraform, so apologize if this is a straightforward problem!

Seems like I got it working with this syntax, but only using a “name” reference, not an integrated Terraform resource reference. If anyone knows how to get it to use a Terraform resource reference (to ensure order of build), let me know!

resource "aws_ecs_cluster" "my_ecs_cluster" {
  name = local.ecs_cluster_name
  capacity_providers = [for key, value in local.services : key]
}