Skip to content

Commit

Permalink
Merge pull request #2208 from quixoticmonk/fix/datasources-pagination
Browse files Browse the repository at this point in the history
fix: pagination on plural datasources
  • Loading branch information
jar-b authored Feb 18, 2025
2 parents 24f2b4e + 9f319d9 commit ed8362f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions internal/service/cloudcontrol/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func ListResourcesByTypeName(ctx context.Context, conn *cloudcontrol.Client, rol
"cfTypeName": typeName,
})

var resourceDescriptions []types.ResourceDescription
input := &cloudcontrol.ListResourcesInput{
TypeName: aws.String(typeName),
}
Expand All @@ -26,15 +27,19 @@ func ListResourcesByTypeName(ctx context.Context, conn *cloudcontrol.Client, rol
input.RoleArn = aws.String(roleARN)
}

output, err := conn.ListResources(ctx, input)
paginator := cloudcontrol.NewListResourcesPaginator(conn, input)
for paginator.HasMorePages() {
page, err := paginator.NextPage(ctx)
if err != nil {
return nil, err
}

if err != nil {
return nil, err
resourceDescriptions = append(resourceDescriptions, page.ResourceDescriptions...)
}

if output == nil {
if len(resourceDescriptions) == 0 {
return nil, &tfresource.NotFoundError{Message: "Empty result"}
}

return output.ResourceDescriptions, nil
return resourceDescriptions, nil
}

0 comments on commit ed8362f

Please sign in to comment.