From ffe99d0f80a0b4034cc749fe4ea4a15e1e919584 Mon Sep 17 00:00:00 2001 From: Matt Calhoun Date: Tue, 30 Aug 2022 06:17:28 -0400 Subject: [PATCH] fix pagination bug (#35) --- internal/service/securityhub/find.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/internal/service/securityhub/find.go b/internal/service/securityhub/find.go index 3dab779..babae94 100644 --- a/internal/service/securityhub/find.go +++ b/internal/service/securityhub/find.go @@ -46,21 +46,28 @@ func FindSecurityHubControl(conn *securityhub.SecurityHub, controlArn string) (* StandardsSubscriptionArn: s.StandardsSubscriptionArn, } - controls, err := conn.DescribeStandardsControls(input) - - for _, c := range controls.Controls { - if *c.StandardsControlArn == controlArn { - return c, nil + var foundControl *securityhub.StandardsControl + err := conn.DescribeStandardsControlsPages(input, func(page *securityhub.DescribeStandardsControlsOutput, lastPage bool) bool { + for _, c := range page.Controls { + if *c.StandardsControlArn == controlArn { + foundControl = c + return false + } } - } + return !lastPage + }) if err != nil { return nil, err } + + if foundControl != nil { + return foundControl, nil + } } return nil, &resource.NotFoundError{ - Message: fmt.Sprintf("%s is not a valid control arn", controlArn), + Message: fmt.Sprintf("Could not find a control with arn %s", controlArn), } }