From fa9399556ba8a25d22c68b995af00a6f699361d9 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 17 Jun 2024 09:08:40 -0400 Subject: [PATCH 1/4] Add 'ci.semgrep.migrate.paginator-more-pages' rule. --- .ci/semgrep/migrate/paginator.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .ci/semgrep/migrate/paginator.yml diff --git a/.ci/semgrep/migrate/paginator.yml b/.ci/semgrep/migrate/paginator.yml new file mode 100644 index 00000000000..cc65b5dbe2e --- /dev/null +++ b/.ci/semgrep/migrate/paginator.yml @@ -0,0 +1,7 @@ +rules: + - id: paginator-more-pages + languages: [go] + message: Use `for pages.HasMorePages()`, not `if pages.HasMorePages()` + patterns: + - pattern-regex: 'if\s+pages\.HasMorePages\(\)' + severity: ERROR From bcbf6ab112f21dee644558708e8f81ded0fc9255 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 17 Jun 2024 09:11:06 -0400 Subject: [PATCH 2/4] Fix 'ci.semgrep.migrate.paginator-more-pages'. --- internal/service/ec2/findv2.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/service/ec2/findv2.go b/internal/service/ec2/findv2.go index 59d893b5c91..1160e5fa96e 100644 --- a/internal/service/ec2/findv2.go +++ b/internal/service/ec2/findv2.go @@ -3209,7 +3209,7 @@ func findTransitGateways(ctx context.Context, conn *ec2.Client, input *ec2.Descr var output []awstypes.TransitGateway pages := ec2.NewDescribeTransitGatewaysPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayIDNotFound) { @@ -3271,7 +3271,7 @@ func findTransitGatewayAttachments(ctx context.Context, conn *ec2.Client, input var output []awstypes.TransitGatewayAttachment pages := ec2.NewDescribeTransitGatewayAttachmentsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayAttachmentIDNotFound) { @@ -3326,7 +3326,7 @@ func findTransitGatewayConnects(ctx context.Context, conn *ec2.Client, input *ec var output []awstypes.TransitGatewayConnect pages := ec2.NewDescribeTransitGatewayConnectsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayAttachmentIDNotFound) { @@ -3393,7 +3393,7 @@ func findTransitGatewayConnectPeers(ctx context.Context, conn *ec2.Client, input var output []awstypes.TransitGatewayConnectPeer pages := ec2.NewDescribeTransitGatewayConnectPeersPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayConnectPeerIDNotFound) { @@ -3455,7 +3455,7 @@ func findTransitGatewayMulticastDomains(ctx context.Context, conn *ec2.Client, i var output []awstypes.TransitGatewayMulticastDomain pages := ec2.NewDescribeTransitGatewayMulticastDomainsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayMulticastDomainIdNotFound) { @@ -3517,7 +3517,7 @@ func findTransitGatewayMulticastDomainAssociations(ctx context.Context, conn *ec var output []awstypes.TransitGatewayMulticastDomainAssociation pages := ec2.NewGetTransitGatewayMulticastDomainAssociationsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayMulticastDomainIdNotFound) { @@ -3573,7 +3573,7 @@ func findTransitGatewayMulticastGroups(ctx context.Context, conn *ec2.Client, in var output []awstypes.TransitGatewayMulticastGroup pages := ec2.NewSearchTransitGatewayMulticastGroupsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayMulticastDomainIdNotFound) { @@ -3682,7 +3682,7 @@ func findTransitGatewayPeeringAttachments(ctx context.Context, conn *ec2.Client, var output []awstypes.TransitGatewayPeeringAttachment pages := ec2.NewDescribeTransitGatewayPeeringAttachmentsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayAttachmentIDNotFound) { @@ -3748,7 +3748,7 @@ func findTransitGatewayPrefixListReferences(ctx context.Context, conn *ec2.Clien var output []awstypes.TransitGatewayPrefixListReference pages := ec2.NewGetTransitGatewayPrefixListReferencesPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidRouteTableIDNotFound) { @@ -3870,7 +3870,7 @@ func findTransitGatewayPolicyTables(ctx context.Context, conn *ec2.Client, input var output []awstypes.TransitGatewayPolicyTable pages := ec2.NewDescribeTransitGatewayPolicyTablesPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayPolicyTableIdNotFound) { @@ -3894,7 +3894,7 @@ func findTransitGatewayRouteTables(ctx context.Context, conn *ec2.Client, input var output []awstypes.TransitGatewayRouteTable pages := ec2.NewDescribeTransitGatewayRouteTablesPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidRouteTableIDNotFound) { @@ -4039,7 +4039,7 @@ func findTransitGatewayPolicyTableAssociations(ctx context.Context, conn *ec2.Cl var output []awstypes.TransitGatewayPolicyTableAssociation pages := ec2.NewGetTransitGatewayPolicyTableAssociationsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayPolicyTableIdNotFound) { @@ -4073,7 +4073,7 @@ func findTransitGatewayRouteTableAssociations(ctx context.Context, conn *ec2.Cli var output []awstypes.TransitGatewayRouteTableAssociation pages := ec2.NewGetTransitGatewayRouteTableAssociationsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidRouteTableIDNotFound) { @@ -4138,7 +4138,7 @@ func findTransitGatewayRouteTablePropagations(ctx context.Context, conn *ec2.Cli var output []awstypes.TransitGatewayRouteTablePropagation pages := ec2.NewGetTransitGatewayRouteTablePropagationsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidRouteTableIDNotFound) { @@ -4172,7 +4172,7 @@ func findTransitGatewayVPCAttachments(ctx context.Context, conn *ec2.Client, inp var output []awstypes.TransitGatewayVpcAttachment pages := ec2.NewDescribeTransitGatewayVpcAttachmentsPaginator(conn, input) - if pages.HasMorePages() { + for pages.HasMorePages() { page, err := pages.NextPage(ctx) if tfawserr.ErrCodeEquals(err, errCodeInvalidTransitGatewayAttachmentIDNotFound) { From 177d21509e3799c00e20ded0dda012d67be54e29 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 17 Jun 2024 09:14:50 -0400 Subject: [PATCH 3/4] Add CHANGELOG entry. --- .changelog/#####.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/#####.txt diff --git a/.changelog/#####.txt b/.changelog/#####.txt new file mode 100644 index 00000000000..29f38daa2fc --- /dev/null +++ b/.changelog/#####.txt @@ -0,0 +1,3 @@ +```release-note:bug +service/transitgateway: Fix resource Read pagination regression causing `NotFound` errors +``` \ No newline at end of file From 547c0f9db42feec383e7a1fc68945539e16d1c83 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 17 Jun 2024 09:17:51 -0400 Subject: [PATCH 4/4] Correct CHANGELOG entry file name. --- .changelog/{#####.txt => 38011.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{#####.txt => 38011.txt} (100%) diff --git a/.changelog/#####.txt b/.changelog/38011.txt similarity index 100% rename from .changelog/#####.txt rename to .changelog/38011.txt