From c3d987ab18fd794c37d7feeb71405e7f09a6c189 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Tue, 22 Dec 2015 12:05:01 -0600 Subject: [PATCH 1/3] VPC Endpoint test updates --- .../aws/resource_aws_vpc_endpoint_test.go | 24 ++++++++----------- ...esource_aws_vpc_peering_connection_test.go | 3 +++ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_endpoint_test.go b/builtin/providers/aws/resource_aws_vpc_endpoint_test.go index 7973cf8f00..4a081b69c0 100644 --- a/builtin/providers/aws/resource_aws_vpc_endpoint_test.go +++ b/builtin/providers/aws/resource_aws_vpc_endpoint_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" "github.com/hashicorp/terraform/helper/resource" @@ -20,9 +21,9 @@ func TestAccAWSVpcEndpoint_basic(t *testing.T) { CheckDestroy: testAccCheckVpcEndpointDestroy, Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccVpcEndpointConfig, + Config: testAccVpcEndpointWithRouteTableAndPolicyConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckVpcEndpointExists("aws_vpc_endpoint.private-s3", &endpoint), + testAccCheckVpcEndpointExists("aws_vpc_endpoint.second-private-s3", &endpoint), ), }, }, @@ -69,7 +70,13 @@ func testAccCheckVpcEndpointDestroy(s *terraform.State) error { VpcEndpointIds: []*string{aws.String(rs.Primary.ID)}, } resp, err := conn.DescribeVpcEndpoints(input) - + if err != nil { + // Verify the error is what we want + if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidVpcEndpointId.NotFound" { + continue + } + return err + } if len(resp.VpcEndpoints) > 0 { return fmt.Errorf("VPC Endpoints still exist.") } @@ -109,17 +116,6 @@ func testAccCheckVpcEndpointExists(n string, endpoint *ec2.VpcEndpoint) resource } } -const testAccVpcEndpointConfig = ` -resource "aws_vpc" "foo" { - cidr_block = "10.1.0.0/16" -} - -resource "aws_vpc_endpoint" "private-s3" { - vpc_id = "${aws_vpc.foo.id}" - service_name = "com.amazonaws.us-west-2.s3" -} -` - const testAccVpcEndpointWithRouteTableAndPolicyConfig = ` resource "aws_vpc" "foo" { cidr_block = "10.0.0.0/16" diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go index ca92ce66a6..48f8bee850 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go @@ -37,6 +37,9 @@ func TestAccAWSVPCPeeringConnection_basic(t *testing.T) { func TestAccAWSVPCPeeringConnection_tags(t *testing.T) { var connection ec2.VpcPeeringConnection peerId := os.Getenv("TF_PEER_ID") + if peerId == "" { + t.Fatalf("Error: TestAccAWSVPCPeeringConnection_tags requires a peer id to be set") + } resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, From 70bb536be10952452aa3ac54d8881a74c579621b Mon Sep 17 00:00:00 2001 From: clint shryock Date: Tue, 22 Dec 2015 12:18:22 -0600 Subject: [PATCH 2/3] skip TestAccAWSVPCPeeringConnection_tags for now --- .../providers/aws/resource_aws_vpc_peering_connection_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go index 48f8bee850..7e85659f2e 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go @@ -38,7 +38,7 @@ func TestAccAWSVPCPeeringConnection_tags(t *testing.T) { var connection ec2.VpcPeeringConnection peerId := os.Getenv("TF_PEER_ID") if peerId == "" { - t.Fatalf("Error: TestAccAWSVPCPeeringConnection_tags requires a peer id to be set") + t.Skip("Error: TestAccAWSVPCPeeringConnection_tags requires a peer id to be set") } resource.Test(t, resource.TestCase{ From 558e839bf28c67d81f511ad42f73d02177426c40 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Tue, 22 Dec 2015 12:53:42 -0600 Subject: [PATCH 3/3] vpc vpn connection test fixes --- .../aws/resource_aws_vpn_connection_test.go | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpn_connection_test.go b/builtin/providers/aws/resource_aws_vpn_connection_test.go index 123cb07e6b..cf151fc854 100644 --- a/builtin/providers/aws/resource_aws_vpn_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpn_connection_test.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" "github.com/hashicorp/terraform/helper/resource" @@ -44,8 +45,40 @@ func TestAccAWSVpnConnection_basic(t *testing.T) { } func testAccAwsVpnConnectionDestroy(s *terraform.State) error { - if len(s.RootModule().Resources) > 0 { - return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources) + conn := testAccProvider.Meta().(*AWSClient).ec2conn + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_vpn_connection" { + continue + } + + resp, err := conn.DescribeVpnConnections(&ec2.DescribeVpnConnectionsInput{ + VpnConnectionIds: []*string{aws.String(rs.Primary.ID)}, + }) + + if err != nil { + if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnConnectionID.NotFound" { + // not found + return nil + } + return err + } + + var vpn *ec2.VpnConnection + for _, v := range resp.VpnConnections { + if v.VpnConnectionId != nil && *v.VpnConnectionId == rs.Primary.ID { + vpn = v + } + } + + if vpn == nil { + // vpn connection not found + return nil + } + + if vpn.State != nil && *vpn.State == "deleted" { + return nil + } + } return nil