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

d/ec2_transit_gateway_dx_gateway_attachement - filter support #12516

Conversation

DrFaust92
Copy link
Collaborator

…source

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 #11994

Release note for CHANGELOG:

data_source_aws_ec2_transit_gateway_dx_gateway_attachement  - add filter support

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_'
Cant run these for some reason i get error on delete of the transit gateway:

2020/03/24 23:21:59 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: error deleting EC2 Transit Gateway: IncorrectState: tgw-031b5b37743c10646 has non-deleted DirectConnect Gateway Attachments: tgw-attach-0f0dc47327d18b997.


this error is consistent for me, fails regardless of the change

@DrFaust92 DrFaust92 requested a review from a team March 24, 2020 22:55
@ghost ghost added size/M Managed by automation to categorize the size of a PR. needs-triage Waiting for first response or review from a maintainer. service/directconnect Issues and PRs that pertain to the directconnect service. service/ec2 Issues and PRs that pertain to the ec2 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. documentation Introduces or discusses updates to documentation. labels Mar 24, 2020
@ewbankkit
Copy link
Contributor

My acceptance testing:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_ -timeout 120m
=== RUN   TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_TransitGatewayIdAndDxGatewayId
=== PAUSE TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_TransitGatewayIdAndDxGatewayId
=== RUN   TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter
=== PAUSE TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter
=== CONT  TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_TransitGatewayIdAndDxGatewayId
=== CONT  TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter
--- PASS: TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_TransitGatewayIdAndDxGatewayId (1131.43s)
--- FAIL: TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter (1131.90s)
    testing.go:654: Step 0 error: errors during apply:
        
        Error: error reading EC2 Transit Gateway Direct Connect Gateway Attachment: no results found
        
          on /tmp/tf-test987078030/main.tf line 23:
          (source code not available)
        
        
FAIL
FAIL	github.com/terraform-providers/terraform-provider-aws/aws	1131.949s
FAIL
GNUmakefile:26: recipe for target 'testacc' failed
make: *** [testacc] Error 1

I'll investigate the failure.

@ewbankkit
Copy link
Contributor

Still get the same error if I simplify the relevant code to

	input := &ec2.DescribeTransitGatewayAttachmentsInput{}

	input.Filters = buildEC2AttributeFilterList(map[string]string{
		"resource-type":      ec2.TransitGatewayAttachmentResourceTypeDirectConnectGateway,
		"resource-id":        d.Get("dx_gateway_id").(string),
		"transit-gateway-id": d.Get("transit_gateway_id").(string),
	})
	input.Filters = append(input.Filters, ec2TagFiltersFromMap(d.Get("tags").(map[string]interface{}))...)
	input.Filters = append(input.Filters, buildAwsDataSourceFilters(d.Get("filter").(*schema.Set))...)
	if len(input.Filters) == 0 {
		// Don't send an empty filters list; the EC2 API won't accept it.
		input.Filters = nil
	}

continuing investigation...

@ewbankkit
Copy link
Contributor

It's a dependency ordering in the test. Change

  filter {
    name   = "resource-id"
    values = ["${aws_dx_gateway.test.id}"]
  }

to

  filter {
    name   = "resource-id"
    values = ["${aws_dx_gateway_association.test.dx_gateway_id}"]
  }

and the test passes:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -count 1 -parallel 20 -run=TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter -timeout 120m
=== RUN   TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter
=== PAUSE TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter
=== CONT  TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter
--- PASS: TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter (1153.46s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	1153.500s

as the data source isn't created until the attachment has been created.

@DrFaust92
Copy link
Collaborator Author

Thanks so much @ewbankkit !!!

Ive changed this accordingly

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 26, 2020
@bflad bflad self-assigned this Mar 26, 2020
Comment on lines 55 to 68
// to preserve original functionality
if dxGatewayIdOk && transitGatewayIdOk {
input.Filters = []*ec2.Filter{
{
Name: aws.String("resource-id"),
Values: []*string{aws.String(d.Get("dx_gateway_id").(string))},
Values: []*string{aws.String(dxGatewayId.(string))},
},
{
Name: aws.String("resource-type"),
Values: []*string{aws.String("direct-connect-gateway")}, // Not yet defined in ec2/api.go.
Values: []*string{aws.String(ec2.TransitGatewayAttachmentResourceTypeDirectConnectGateway)},
},
{
Name: aws.String("transit-gateway-id"),
Values: []*string{aws.String(d.Get("transit_gateway_id").(string))},
Values: []*string{aws.String(transitGatewayId.(string))},
},
},
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here as the other PR. 👍 (removing resource-type so its not duplicated in the request)

	if dxGatewayIdOk {
		input.Filters = append(input.Filters, &ec2.Filter{
			Name:   aws.String("resource-id"),
			Values: []*string{aws.String(dxGatewayId.(string))},
		})
	}

	if transitGatewayIdOk {
		input.Filters = append(input.Filters, &ec2.Filter{
			Name:   aws.String("transit-gateway-id"),
			Values: []*string{aws.String(transitGatewayId.(string))},
		})
	}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done + small changes to naming.

--- PASS: TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_TransitGatewayIdAndDxGatewayId (1188.58s)
--- PASS: TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter (1256.65s)

@DrFaust92 DrFaust92 force-pushed the r/ec2_transit_gateway_dx_gateway_attachement_filter branch from c323745 to e96c40a Compare March 26, 2020 15:48
@DrFaust92 DrFaust92 force-pushed the r/ec2_transit_gateway_dx_gateway_attachement_filter branch from e96c40a to 2cf7ea7 Compare March 26, 2020 15:59
@DrFaust92 DrFaust92 requested a review from bflad March 26, 2020 17:54
@bflad bflad added this to the v2.55.0 milestone Mar 26, 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.

Looks great, thanks @DrFaust92 🚀

Output from acceptance testing:

--- PASS: TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_filter (1163.07s)
--- PASS: TestAccAWSEc2TransitGatewayDxGatewayAttachmentDataSource_TransitGatewayIdAndDxGatewayId (1171.51s)

@bflad bflad merged commit 21f49a7 into hashicorp:master Mar 26, 2020
bflad added a commit that referenced this pull request Mar 26, 2020
@ghost
Copy link

ghost commented Mar 27, 2020

This has been released in version 2.55.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 Apr 26, 2020

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 and limited conversation to collaborators Apr 26, 2020
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. enhancement Requests to existing resources that expand the functionality or scope. service/directconnect Issues and PRs that pertain to the directconnect service. service/ec2 Issues and PRs that pertain to the ec2 service. size/M 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.

None yet

3 participants