Search code examples
amazon-web-servicesterraformamazon-ecs

Terraform ECS Data Block Issue


I am creating an AWS alarm using Terraform. In the metrics, I want to fetch the cluster names to monitor multiple resources and create alarms for them. Unfortunately, the 'data' block is asking for a specific name, but I want to fetch all the cluster names. How can I do that? enter image description here

Any suggestion is acceptable


Solution

  • At this time, the Terraform AWS provider does not have a data source for looking up a list of ECS clusters. So there is no way to do what you are asking for with the Terraform AWS provider.

    HashiCorp does provide a lower-level Terraform Provider for interacting with the AWS API called the AWS Cloud Control Provider. That provider does appear to have a data source for looking up a list of ECS clusters. That data source only gives you cluster IDs, but if you need more information than that you could use that list of IDs via a for_each in this other data source that gives you the cluster details.

    So, by including this second Terraform Provider in your Terraform code, you should be able to get the references to all your ECS clusters.