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

Add namevaluesfilters package for resource filtering code #13304

Closed
ewbankkit opened this issue May 13, 2020 · 6 comments · Fixed by #13313
Closed

Add namevaluesfilters package for resource filtering code #13304

ewbankkit opened this issue May 13, 2020 · 6 comments · Fixed by #13313
Labels
enhancement Requests to existing resources that expand the functionality or scope.

Comments

@ewbankkit
Copy link
Contributor

ewbankkit commented May 13, 2020

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

A number of AWS services, for example EC2 and RDS, support generic attribute filtering in APIs' resource Describe calls. The code to manipulate the data structures associated with resource filtering is nearly identical across services and is very amenable to code generation.

Following on from this comment, it make senses to implement such generators in a new namevaluesfilters package.

One possible interface is:

type NameValuesFilters map[string][]string

func New(m map[string][]string) NameValuesFilters

func (NameValuesFilters) AutoscalingFilters() []*autoscaling.Filter
func (NameValuesFilters) DatabasemigrationserviceFilters() []*databasemigrationservice.Filter
func (NameValuesFilters) DocdbFilters() []*docdb.Filter
func (NameValuesFilters) Ec2Filters() []*ec2.Filter
func (NameValuesFilters) FsxFilters() []*fsx.Filter
func (NameValuesFilters) ImagebuilderFilters() []*imagebuilder.Filter
func (NameValuesFilters) LicensemanagerFilters() []*licensemanager.Filter
func (NameValuesFilters) NeptuneFilters() []*neptune.Filter
func (NameValuesFilters) RdsFilters() []*rds.Filter
func (NameValuesFilters) Route53resolverFilters() []*route53resolver.Filter

Definition of Done

Related:

@ewbankkit ewbankkit added the enhancement Requests to existing resources that expand the functionality or scope. label May 13, 2020
@ewbankkit
Copy link
Contributor Author

ewbankkit commented May 17, 2020

The code for data sources such as the aws_vpc data source could be changed to something like

	// Filters based on attributes.
	filters := namevaluesfilters.New(map[string]string{
		"internet-gateway-id": d.Get("internet_gateway_id").(string),
	})
	// Filters based on keyvalue tags.
	filters.Add(namevaluesfilters.Ec2Tags(keyvaluetags.New(d.Get("tags").(map[string]interface{})).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()))
	// Filters based on the custom filtering "filter" attribute.
	filters.Add(d.Get("filter").(*schema.Set))

	req.Filters = filters.Ec2Filters()

@ewbankkit
Copy link
Contributor Author

ewbankkit commented May 26, 2020

Data sources (other than for EC2 resources) that can use this functionality:

  • aws_autoscaling_groups
  • aws_db_cluster_snapshot
  • aws_db_event_categories
  • aws_db_instance
  • aws_db_snapshot
  • aws_route53_resolver_rule
  • aws_route53_resolver_rules

@bflad
Copy link
Contributor

bflad commented Jul 9, 2020

@ewbankkit
Copy link
Contributor Author

ewbankkit commented Jul 10, 2020

Yes, it's effectively the same functionality although the Name field is called Key but the code generator can handle that.
I'll add the aws_secretsmanager_secret data source to the list above.
Requires #14000.
Announcement.

@ewbankkit
Copy link
Contributor Author

I decided not to add the secretsmanager service to the generated code list as the fact that the name field is Key implies we cannot use the standard

		Elem: &schema.Resource{
			Schema: map[string]*schema.Schema{
				"name": {
					Type:     schema.TypeString,
					Required: true,
				},

				"values": {
					Type:     schema.TypeSet,
					Required: true,
					Elem: &schema.Schema{
						Type: schema.TypeString,
					},
				},
			},
		},

definition for the filter attribute.

@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 Sep 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants