-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
New data source: aws_ec2_managed_prefix_list #16738
New data source: aws_ec2_managed_prefix_list #16738
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for splitting this out @roberth-k, just a few things then we should be able to get this in. 👍
|
||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should fix the importlint
error:
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" | |
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" |
|
||
func dataSourceAwsEc2ManagedPrefixList() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceAwsEc2ManagedPrefixListRead, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not quite ready to switch to the Context
versions of the functions everywhere due to some known issues, but this is probably okay.
return &schema.Resource{ | ||
ReadContext: dataSourceAwsEc2ManagedPrefixListRead, | ||
Schema: map[string]*schema.Schema{ | ||
"id": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It would be easier to scan these attributes if they were sorted alphabetically and we may eventually enable tfproviderlint
XS002
filters, filtersOk := d.GetOk("filter") | ||
|
||
input := ec2.DescribeManagedPrefixListsInput{} | ||
|
||
if filtersOk { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Simplification:
filters, filtersOk := d.GetOk("filter") | |
input := ec2.DescribeManagedPrefixListsInput{} | |
if filtersOk { | |
input := ec2.DescribeManagedPrefixListsInput{} | |
if filters, ok := d.GetOk("filter"); ok { |
input.PrefixListIds = aws.StringSlice([]string{prefixListId.(string)}) | ||
} | ||
|
||
if prefixListName := d.Get("name"); prefixListName.(string) != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Simplification:
if prefixListName := d.Get("name"); prefixListName.(string) != "" { | |
if prefixListName, ok := d.GetOk("name"); ok { |
out, err := conn.DescribeManagedPrefixListsWithContext(ctx, &input) | ||
|
||
if err != nil { | ||
return diag.FromErr(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errors should return context for operators and code maintainers. Eventually this should get caught by: #15892
return diag.FromErr(err) | |
return diag.Errorf("error describing EC2 Managed Prefix Lists: %s", err) |
entries := &schema.Set{ | ||
F: schema.HashResource(dataSourceAwsEc2ManagedPrefixListEntrySchema()), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can bypass schema.Set
usage on flattening and just use []interface{}
with append()
👍
) | ||
|
||
if err != nil { | ||
return diag.FromErr(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error context:
return diag.FromErr(err) | |
return diag.Errorf("error getting EC2 Managed Prefix List (%s) Entries: %s", d.Id(), err) |
resource "aws_ec2_managed_prefix_list" "example" { | ||
name = "example" | ||
max_entries = 5 | ||
address_family = "IPv4" | ||
|
||
entry { | ||
cidr_block = "1.0.0.0/8" | ||
} | ||
} | ||
|
||
data "aws_ec2_managed_prefix_list" "example" { | ||
filter { | ||
name = "prefix-list-name" | ||
values = [aws_ec2_managed_prefix_list.example.name] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resource does not exist yet and we prefer not showing the anti-pattern of having a data source reference a managed resource:
resource "aws_ec2_managed_prefix_list" "example" { | |
name = "example" | |
max_entries = 5 | |
address_family = "IPv4" | |
entry { | |
cidr_block = "1.0.0.0/8" | |
} | |
} | |
data "aws_ec2_managed_prefix_list" "example" { | |
filter { | |
name = "prefix-list-name" | |
values = [aws_ec2_managed_prefix_list.example.name] | |
} | |
} | |
data "aws_ec2_managed_prefix_list" "example" { | |
filter { | |
name = "prefix-list-name" | |
values = ["example"] | |
} | |
} |
Please note that I've updated the milestone for this pull request to version 3.22.0, which we expect to release on Thursday as our last release before the new year so its not lingering over the long break. If we do not see the updates prior to Wednesday, we will add commits on top of the existing ones to ensure this is tested and merged in time. 👍 |
b9107da
to
9785852
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks @roberth-k 🚀
Output from acceptance testing in AWS Commercial:
--- PASS: TestAccDataSourceAwsEc2ManagedPrefixList_matchesTooMany (2.82s)
--- PASS: TestAccDataSourceAwsEc2ManagedPrefixList_basic (14.10s)
--- PASS: TestAccDataSourceAwsEc2ManagedPrefixList_filter (15.01s)
Output from acceptance testing in AWS GovCloud (US):
=== CONT TestAccDataSourceAwsEc2ManagedPrefixList_filter
data_source_aws_ec2_managed_prefix_list_test.go:100: Step 1/1 error: Error running pre-apply refresh:
Error: error describing EC2 Managed Prefix Lists: InvalidAction: The action DescribeManagedPrefixLists is not valid for this web service.
status code: 400, request id: 7216f4c9-169f-4097-95ac-1bd62806bd30
=== CONT TestAccDataSourceAwsEc2ManagedPrefixList_basic
data_source_aws_ec2_managed_prefix_list_test.go:46: Step 1/1 error: Error running pre-apply refresh:
Error: error describing EC2 Managed Prefix Lists: InvalidAction: The action DescribeManagedPrefixLists is not valid for this web service.
status code: 400, request id: bf128192-6ee8-424b-ace3-09349efa30d2
=== CONT TestAccDataSourceAwsEc2ManagedPrefixList_matchesTooMany
data_source_aws_ec2_managed_prefix_list_test.go:151: Step 1/1, expected an error with pattern, no match on: Error running pre-apply refresh:
Error: error describing EC2 Managed Prefix Lists: InvalidAction: The action DescribeManagedPrefixLists is not valid for this web service.
status code: 400, request id: e7e70397-1865-4b83-b569-c9800f1bf29f
--- FAIL: TestAccDataSourceAwsEc2ManagedPrefixList_filter (4.08s)
--- FAIL: TestAccDataSourceAwsEc2ManagedPrefixList_basic (4.11s)
--- FAIL: TestAccDataSourceAwsEc2ManagedPrefixList_matchesTooMany (4.11s)
Created followup issue for GovCloud testing: #16804
Is this going to make it in the release today? |
This has been released in version 3.22.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Community Note
Relates #13986
Tests should be expanded when the
aws_ec2_managed_prefix_list
resource in #14068 has been merged.Release note for CHANGELOG:
Output from acceptance testing: