Is it possible in Terraform to retrieve AWS resources by tag? (see tagged resource API)
I would like to retrieve ECR, Target Groups, Load Balancers etc. by tag, e.g.:
data "aws_alb_listener" "my_listener" {
tag = "my-unique-tag"
}
Please see the documentation
This is not implemented by now, you could propably file a pull request to get this implemented.
I can understand the implications that there might be multiple resources with the same tag available. Which one to choose then? The first you find? Ideally, we want to support even multiple tags like:
data "aws_alb_listener" "my_listener" {
tags {
"my-unique-tag": "*",
"another-tag": "specific value"
}
}
I'll have a look if I create a PR for this.
I ran into this gap in functionality yesterday. It would be great to combine the resource tagging API with these data sources to enable robust discovery of ELBs, ASGs, and other resources rather than being required to know their ID (since their ID is actually the value that's harder to find, especially ELBv2 ARNs). There are already data sources that lookup multiple (or no) IDs by tags (eg aws_subnet_ids). Or I'm guessing with TF 0.12's better type support, you could return arrays of entire resources.
Thank you for using Terraform and for opening up this question. Issues on GitHub are intended to be related to bugs or feature requests with the provider codebase. Feedback was provided in the thread, and pull requests are always welcome! If additional feedback or discussion is needed, please use https://discuss.hashicorp.com/c/terraform-providers.
If you believe that your issue was miscategorized as a question or closed in error, please create a new issue using one of the following provided templates: bug report or feature request. Please make sure to provide us with the appropriate information so we can best determine how to assist with the given issue.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!