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

Bugfix: Use DescribeManagedPrefixListsPagesWithContext to get prefix list #26683

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions .changelog/26683.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_ec2_managed_prefix_list: Fixes bug where an error is returned for regions with more than 100 managed prefix lists
```
16 changes: 12 additions & 4 deletions internal/service/ec2/vpc_managed_prefix_list_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,29 @@ func dataSourceManagedPrefixListRead(ctx context.Context, d *schema.ResourceData
})
}

out, err := conn.DescribeManagedPrefixListsWithContext(ctx, &input)
var prefixLists []*ec2.ManagedPrefixList

err := conn.DescribeManagedPrefixListsPagesWithContext(
ctx,
&input,
func(output *ec2.DescribeManagedPrefixListsOutput, lastPage bool) bool {
prefixLists = append(prefixLists, output.PrefixLists...)
return !lastPage
})

if err != nil {
return diag.Errorf("error describing EC2 Managed Prefix Lists: %s", err)
}

if out == nil || len(out.PrefixLists) < 1 || out.PrefixLists[0] == nil {
if len(prefixLists) < 1 || prefixLists[0] == nil {
return diag.Errorf("no managed prefix lists matched the given criteria")
}

if len(out.PrefixLists) > 1 {
if len(prefixLists) > 1 {
return diag.Errorf("more than 1 prefix list matched the given criteria")
}

pl := out.PrefixLists[0]
pl := prefixLists[0]

d.SetId(aws.StringValue(pl.PrefixListId))
d.Set("name", pl.PrefixListName)
Expand Down