From aa467e8119cb7a932ed1b1a8306d77d2b4e4eb5c Mon Sep 17 00:00:00 2001 From: Jon Shea Date: Thu, 19 Aug 2021 15:05:41 -0400 Subject: [PATCH 1/4] Patch resolver rule data source to paginate --- aws/data_source_aws_route53_resolver_rule.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/aws/data_source_aws_route53_resolver_rule.go b/aws/data_source_aws_route53_resolver_rule.go index faf941156b3..d1555fd37e2 100644 --- a/aws/data_source_aws_route53_resolver_rule.go +++ b/aws/data_source_aws_route53_resolver_rule.go @@ -105,18 +105,20 @@ func dataSourceAwsRoute53ResolverRuleRead(d *schema.ResourceData, meta interface } 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 { + if len(page.ResolverRules) > 0 { + rule = page.ResolverRules[0] + return false + } + 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 rule == nil { 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] } d.SetId(aws.StringValue(rule.Id)) From 720950842752dc4c22d36986170272f9866aa455 Mon Sep 17 00:00:00 2001 From: Jon Shea Date: Fri, 20 Aug 2021 11:51:40 -0400 Subject: [PATCH 2/4] Maintain errors for too many matching rules --- aws/data_source_aws_route53_resolver_rule.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/aws/data_source_aws_route53_resolver_rule.go b/aws/data_source_aws_route53_resolver_rule.go index d1555fd37e2..4369ca6e6cc 100644 --- a/aws/data_source_aws_route53_resolver_rule.go +++ b/aws/data_source_aws_route53_resolver_rule.go @@ -104,21 +104,22 @@ func dataSourceAwsRoute53ResolverRuleRead(d *schema.ResourceData, meta interface }), } + rules := []*route53resolver.ResolverRule{} log.Printf("[DEBUG] Listing Route53 Resolver rules: %s", req) err := conn.ListResolverRulesPages(req, func(page *route53resolver.ListResolverRulesOutput, lastPage bool) bool { - if len(page.ResolverRules) > 0 { - rule = page.ResolverRules[0] - return false - } + rules = append(rules, page.ResolverRules...) return !lastPage }) if err != nil { return fmt.Errorf("error getting Route53 Resolver rule: %w", err) } - - if rule == nil { + 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 = rules[0] } d.SetId(aws.StringValue(rule.Id)) From bcaddc8d322aed41b5bcc375d0997c8d6c75e5db Mon Sep 17 00:00:00 2001 From: Jon Shea Date: Fri, 20 Aug 2021 13:34:52 -0400 Subject: [PATCH 3/4] Add changelog entry --- .changelog/20642.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/20642.txt diff --git a/.changelog/20642.txt b/.changelog/20642.txt new file mode 100644 index 00000000000..49bc31f50a7 --- /dev/null +++ b/.changelog/20642.txt @@ -0,0 +1,3 @@ +```release-note:bug +data-source/aws_route53_resolver_rule: Fix lack of pagination when listing rules +``` \ No newline at end of file From d66602109e11be7d72846161f4653fa0a3ef855c Mon Sep 17 00:00:00 2001 From: Jon Shea Date: Fri, 20 Aug 2021 13:46:00 -0400 Subject: [PATCH 4/4] Undo accidental string modification --- aws/data_source_aws_route53_resolver_rule.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/data_source_aws_route53_resolver_rule.go b/aws/data_source_aws_route53_resolver_rule.go index 4369ca6e6cc..4a094939d55 100644 --- a/aws/data_source_aws_route53_resolver_rule.go +++ b/aws/data_source_aws_route53_resolver_rule.go @@ -111,7 +111,7 @@ func dataSourceAwsRoute53ResolverRuleRead(d *schema.ResourceData, meta interface return !lastPage }) if err != nil { - return fmt.Errorf("error getting Route53 Resolver rule: %w", err) + return fmt.Errorf("error getting Route53 Resolver rules: %w", err) } if n := len(rules); n == 0 { return fmt.Errorf("no Route53 Resolver rules matched")