Merge pull request #4422 from hashicorp/b-vpc-endpoint-updates

VPC Endpoint test updates
This commit is contained in:
Clint 2015-12-22 15:46:59 -06:00
commit c49802de87
3 changed files with 48 additions and 16 deletions

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/aws/aws-sdk-go/aws" "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/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -20,9 +21,9 @@ func TestAccAWSVpcEndpoint_basic(t *testing.T) {
CheckDestroy: testAccCheckVpcEndpointDestroy, CheckDestroy: testAccCheckVpcEndpointDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
resource.TestStep{ resource.TestStep{
Config: testAccVpcEndpointConfig, Config: testAccVpcEndpointWithRouteTableAndPolicyConfig,
Check: resource.ComposeTestCheckFunc( 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)}, VpcEndpointIds: []*string{aws.String(rs.Primary.ID)},
} }
resp, err := conn.DescribeVpcEndpoints(input) 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 { if len(resp.VpcEndpoints) > 0 {
return fmt.Errorf("VPC Endpoints still exist.") 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 = ` const testAccVpcEndpointWithRouteTableAndPolicyConfig = `
resource "aws_vpc" "foo" { resource "aws_vpc" "foo" {
cidr_block = "10.0.0.0/16" cidr_block = "10.0.0.0/16"

View File

@ -37,6 +37,9 @@ func TestAccAWSVPCPeeringConnection_basic(t *testing.T) {
func TestAccAWSVPCPeeringConnection_tags(t *testing.T) { func TestAccAWSVPCPeeringConnection_tags(t *testing.T) {
var connection ec2.VpcPeeringConnection var connection ec2.VpcPeeringConnection
peerId := os.Getenv("TF_PEER_ID") peerId := os.Getenv("TF_PEER_ID")
if peerId == "" {
t.Skip("Error: TestAccAWSVPCPeeringConnection_tags requires a peer id to be set")
}
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/aws/aws-sdk-go/aws" "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/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -44,8 +45,40 @@ func TestAccAWSVpnConnection_basic(t *testing.T) {
} }
func testAccAwsVpnConnectionDestroy(s *terraform.State) error { func testAccAwsVpnConnectionDestroy(s *terraform.State) error {
if len(s.RootModule().Resources) > 0 { conn := testAccProvider.Meta().(*AWSClient).ec2conn
return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources) 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 return nil