Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service/ec2/find: update call toDescribeRouteTables with paginated method #21710

Merged
merged 3 commits into from
Nov 11, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changelog/21710.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```release-note:bug
data-source/aws_route: Fix lack of pagination when describing route tables
```

```release-note:bug
resource/aws_default_route_table: Fix lack of pagination when describing route tables
```

```release-note:bug
resource/aws_route_table: Fix lack of pagination when describing route tables
```
Comment on lines +1 to +11
Copy link
Contributor Author

@anGie44 anGie44 Nov 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding in these in case to reflect the change affects additional resources that reference the underlying find method


```release-note:bug
resource/aws_route_table_association: Fix lack of pagination when describing route tables
```
22 changes: 19 additions & 3 deletions internal/service/ec2/find.go
Original file line number Diff line number Diff line change
@@ -447,7 +447,23 @@ func FindRouteTableByID(conn *ec2.EC2, routeTableID string) (*ec2.RouteTable, er
}

func FindRouteTable(conn *ec2.EC2, input *ec2.DescribeRouteTablesInput) (*ec2.RouteTable, error) {
anGie44 marked this conversation as resolved.
Show resolved Hide resolved
output, err := conn.DescribeRouteTables(input)
var results []*ec2.RouteTable // only expect to find and return 1

err := conn.DescribeRouteTablesPages(input, func(page *ec2.DescribeRouteTablesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}

for _, table := range page.RouteTables {
if table == nil {
continue
}

results = append(results, table)
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, ErrCodeInvalidRouteTableIDNotFound) {
return nil, &resource.NotFoundError{
@@ -460,11 +476,11 @@ func FindRouteTable(conn *ec2.EC2, input *ec2.DescribeRouteTablesInput) (*ec2.Ro
return nil, err
}

if output == nil || len(output.RouteTables) == 0 || output.RouteTables[0] == nil {
if len(results) == 0 {
return nil, tfresource.NewEmptyResultError(input)
}

return output.RouteTables[0], nil
return results[0], nil
}

// RouteFinder returns the route corresponding to the specified destination.