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

resource/aws_ec2_transit_gateway_route: Prevent crash with externally removed attachment #7117

Merged
merged 1 commit into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion aws/resource_aws_ec2_transit_gateway_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func resourceAwsEc2TransitGatewayRouteRead(d *schema.ResourceData, meta interfac
d.Set("destination_cidr_block", transitGatewayRoute.DestinationCidrBlock)

d.Set("transit_gateway_attachment_id", "")
if len(transitGatewayRoute.TransitGatewayAttachments) == 0 || transitGatewayRoute.TransitGatewayAttachments[0] != nil {
if len(transitGatewayRoute.TransitGatewayAttachments) > 0 && transitGatewayRoute.TransitGatewayAttachments[0] != nil {
d.Set("transit_gateway_attachment_id", transitGatewayRoute.TransitGatewayAttachments[0].TransitGatewayAttachmentId)
}

Expand Down
27 changes: 27 additions & 0 deletions aws/resource_aws_ec2_transit_gateway_route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,33 @@ func TestAccAWSEc2TransitGatewayRoute_disappears(t *testing.T) {
})
}

func TestAccAWSEc2TransitGatewayRoute_disappears_TransitGatewayAttachment(t *testing.T) {
var transitGateway1 ec2.TransitGateway
var transitGatewayRoute1 ec2.TransitGatewayRoute
var transitGatewayVpcAttachment1 ec2.TransitGatewayVpcAttachment
resourceName := "aws_ec2_transit_gateway_route.test"
transitGatewayVpcAttachmentResourceName := "aws_ec2_transit_gateway_vpc_attachment.test"
transitGatewayResourceName := "aws_ec2_transit_gateway.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSEc2TransitGateway(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSEc2TransitGatewayRouteDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSEc2TransitGatewayRouteConfigDestinationCidrBlock(),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSEc2TransitGatewayExists(transitGatewayResourceName, &transitGateway1),
testAccCheckAWSEc2TransitGatewayRouteExists(resourceName, &transitGatewayRoute1),
testAccCheckAWSEc2TransitGatewayVpcAttachmentExists(transitGatewayVpcAttachmentResourceName, &transitGatewayVpcAttachment1),
testAccCheckAWSEc2TransitGatewayVpcAttachmentDisappears(&transitGatewayVpcAttachment1),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func testAccCheckAWSEc2TransitGatewayRouteExists(resourceName string, transitGatewayRoute *ec2.TransitGatewayRoute) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down