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 pagination to aws_route53_resolver_rule data source #20642

Merged
merged 5 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/20642.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_route53_resolver_rule: Fix lack of pagination when listing rules
```
13 changes: 8 additions & 5 deletions aws/data_source_aws_route53_resolver_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,22 @@ func dataSourceAwsRoute53ResolverRuleRead(d *schema.ResourceData, meta interface
}),
}

rules := []*route53resolver.ResolverRule{}
log.Printf("[DEBUG] Listing Route53 Resolver rules: %s", req)
resp, err := conn.ListResolverRules(req)
err := conn.ListResolverRulesPages(req, func(page *route53resolver.ListResolverRulesOutput, lastPage bool) bool {
rules = append(rules, page.ResolverRules...)
return !lastPage
})
if err != nil {
return fmt.Errorf("error getting Route53 Resolver rules: %w", err)
return fmt.Errorf("error getting Route53 Resolver rule: %w", err)
}

if n := len(resp.ResolverRules); n == 0 {
if n := len(rules); n == 0 {
return fmt.Errorf("no Route53 Resolver rules matched")
} else if n > 1 {
return fmt.Errorf("%d Route53 Resolver rules matched; use additional constraints to reduce matches to a rule", n)
}

rule = resp.ResolverRules[0]
rule = rules[0]
}

d.SetId(aws.StringValue(rule.Id))
Expand Down