Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic Fetching Resources via Tags #17705

Closed
DrFaust92 opened this issue Feb 19, 2021 · 3 comments · Fixed by #17804
Closed

Generic Fetching Resources via Tags #17705

DrFaust92 opened this issue Feb 19, 2021 · 3 comments · Fixed by #17804
Labels
new-data-source Introduces a new data source. service/resourcegroupstaggingapi Issues and PRs that pertain to the resourcegroupstaggingapi service.
Milestone

Comments

@DrFaust92
Copy link
Collaborator

DrFaust92 commented Feb 19, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

In many cases it is easier to group resources using tags rather than keeping hard coded lists of resources by their id (which may differ in connection from service to service)

There are multiple feature requests to fetch resource by filter them through tags. A non exhaustive list of those are:

Some of the service do not implement that kind of filtering on the API level which would require building some custom logic to filter that which may differ from resource to resource based on the API response. that may introduce a maintenance burden, and my break in a future release of the AWS SDK/API Change.

Having the ability to fetch a group of resources (from the same type or even for multiple types at once to make code more DRY) may be beneficial for a multitude of case. for example adding cloudwatch log group to a group of resource based on their id instead of iterating a few separate data sources.

AWS has a single generic API to fetch multiple resource types (or single by filter) and filter them by tags. This will make Terraform config more DRY and will reduce amount of API calls (which in turn reduce various throttling and wait issues).

The way to do it is use the Resource Groups Tagging API

New or Affected Resource(s)

  • aws_resource_groups_tagging

Potential Terraform Configuration

data "aws_ aws_resourcegroupstagging_resources" "filter" {
  resource_type_filters = ["elbv2:loadbalancer"]

  tag_filters {
    key = "tag_key_1"
  }

  tag_filters {
    key = "tag_key_2"
    values = ["tag_value_1", "tag_value_2"]
  }
}

data "aws_alb" "alb_test_with_arn" {
  for_each = data.aws_resource_groups_tagging.filter.resource_tag_mapping_list

  arn = each.resource_arn
}

References

@DrFaust92 DrFaust92 added enhancement Requests to existing resources that expand the functionality or scope. proposal Proposes new design or functionality. labels Feb 19, 2021
@ghost ghost added the service/elbv2 Issues and PRs that pertain to the elbv2 service. label Feb 19, 2021
@DrFaust92 DrFaust92 removed the service/elbv2 Issues and PRs that pertain to the elbv2 service. label Feb 19, 2021
@DrFaust92 DrFaust92 changed the title Fetching Resources via Tags Generic Fetching Resources via Tags Feb 19, 2021
@ghost ghost added the service/elbv2 Issues and PRs that pertain to the elbv2 service. label Feb 19, 2021
@DrFaust92 DrFaust92 removed the service/elbv2 Issues and PRs that pertain to the elbv2 service. label Feb 19, 2021
@bflad bflad added new-data-source Introduces a new data source. service/resourcegroups Issues and PRs that pertain to the resourcegroups service. and removed enhancement Requests to existing resources that expand the functionality or scope. proposal Proposes new design or functionality. labels Feb 19, 2021
@bflad
Copy link
Contributor

bflad commented Feb 19, 2021

I personally think this is a good solution to offer since the API support already exists. My only suggestion would be to name it aws_resourcegroupstagging_resources to match our naming standards a little better ("api" and "service" in the service naming we generally have smoothed over) 👍 .

@ghost ghost added the service/elbv2 Issues and PRs that pertain to the elbv2 service. label Feb 19, 2021
@DrFaust92 DrFaust92 removed the service/elbv2 Issues and PRs that pertain to the elbv2 service. label Feb 19, 2021
@DrFaust92 DrFaust92 added service/resourcegroupstaggingapi Issues and PRs that pertain to the resourcegroupstaggingapi service. and removed service/resourcegroups Issues and PRs that pertain to the resourcegroups service. labels Feb 25, 2021
@github-actions github-actions bot added this to the v3.38.0 milestone Apr 29, 2021
@ghost
Copy link

ghost commented Apr 30, 2021

This has been released in version 3.38.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
new-data-source Introduces a new data source. service/resourcegroupstaggingapi Issues and PRs that pertain to the resourcegroupstaggingapi service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants