Skip to content

Commit

Permalink
Merge pull request #20642 from sheacloud/b-resolver-rule-data-pagination
Browse files Browse the repository at this point in the history
Add pagination to aws_route53_resolver_rule data source
  • Loading branch information
ewbankkit authored Aug 20, 2021
2 parents ee2e043 + d666021 commit 2b12ec1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
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
```
11 changes: 7 additions & 4 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)
}

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

0 comments on commit 2b12ec1

Please sign in to comment.