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

New data source: aws_ec2_managed_prefix_list #16738

Merged
merged 2 commits into from
Dec 17, 2020

Conversation

roberth-k
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates #13986

Tests should be expanded when the aws_ec2_managed_prefix_list resource in #14068 has been merged.

Release note for CHANGELOG:

FEATURES:
- **New Data Source:** `aws_ec2_managed_prefix_list`

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS=-run=TestAccDataSourceAwsEc2ManagedPrefixList
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccDataSourceAwsEc2ManagedPrefixList -timeout 120m
--- PASS: TestAccDataSourceAwsEc2ManagedPrefixList_matchesTooMany (3.60s)
--- PASS: TestAccDataSourceAwsEc2ManagedPrefixList_basic (18.21s)
--- PASS: TestAccDataSourceAwsEc2ManagedPrefixList_filter (18.28s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       19.913s

@roberth-k roberth-k requested a review from a team as a code owner December 13, 2020 16:22
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Dec 13, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Dec 13, 2020
@bflad bflad added new-data-source Introduces a new data source. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 15, 2020
Copy link
Contributor

@bflad bflad left a 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. 👍

Comment on lines 10 to 11

"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
Copy link
Contributor

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:

Suggested change
"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,
Copy link
Contributor

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": {
Copy link
Contributor

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

Comment on lines 77 to 81
filters, filtersOk := d.GetOk("filter")

input := ec2.DescribeManagedPrefixListsInput{}

if filtersOk {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Simplification:

Suggested change
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) != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Simplification:

Suggested change
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)
Copy link
Contributor

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

Suggested change
return diag.FromErr(err)
return diag.Errorf("error describing EC2 Managed Prefix Lists: %s", err)

Comment on lines 124 to 126
entries := &schema.Set{
F: schema.HashResource(dataSourceAwsEc2ManagedPrefixListEntrySchema()),
}
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Error context:

Suggested change
return diag.FromErr(err)
return diag.Errorf("error getting EC2 Managed Prefix List (%s) Entries: %s", d.Id(), err)

Comment on lines 29 to 44
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]
}
}
Copy link
Contributor

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:

Suggested change
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"]
}
}

@bflad bflad added this to the v3.22.0 milestone Dec 15, 2020
@bflad
Copy link
Contributor

bflad commented Dec 15, 2020

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. 👍

@roberth-k roberth-k force-pushed the f-d-aws_ec2_managed_prefix_list branch from b9107da to 9785852 Compare December 16, 2020 15:16
Copy link
Contributor

@bflad bflad left a 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

@bflad bflad merged commit ada2d7d into hashicorp:master Dec 17, 2020
bflad added a commit that referenced this pull request Dec 17, 2020
@jaredready
Copy link

Is this going to make it in the release today?

@ghost
Copy link

ghost commented Dec 18, 2020

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!

@ghost
Copy link

ghost commented Jan 16, 2021

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!

@ghost ghost locked as resolved and limited conversation to collaborators Jan 16, 2021
@roberth-k roberth-k deleted the f-d-aws_ec2_managed_prefix_list branch January 16, 2022 20:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. new-data-source Introduces a new data source. provider Pertains to the provider itself, rather than any interaction with AWS. service/ec2 Issues and PRs that pertain to the ec2 service. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants