diff --git a/builtin/providers/aws/resource_aws_codecommit_repository_test.go b/builtin/providers/aws/resource_aws_codecommit_repository_test.go index 332e2b04a63f..0f7c8da534f7 100644 --- a/builtin/providers/aws/resource_aws_codecommit_repository_test.go +++ b/builtin/providers/aws/resource_aws_codecommit_repository_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/codecommit" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -86,9 +87,24 @@ func testAccCheckCodeCommitRepositoryExists(name string) resource.TestCheckFunc } func testAccCheckCodeCommitRepositoryDestroy(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).codecommitconn + + for _, rs := range s.RootModule().Resources { + if rs.Type != "aws_codecommit_repository" { + continue + } + + _, err := conn.GetRepository(&codecommit.GetRepositoryInput{ + RepositoryName: aws.String(rs.Primary.ID), + }) + + if ae, ok := err.(awserr.Error); ok && ae.Code() == "RepositoryDoesNotExistException" { + continue + } + if err == nil { + return fmt.Errorf("Repository still exists: %s", rs.Primary.ID) + } + return err } return nil diff --git a/builtin/providers/aws/resource_aws_codedeploy_app_test.go b/builtin/providers/aws/resource_aws_codedeploy_app_test.go index 9610a01a7431..6bfa141aea89 100644 --- a/builtin/providers/aws/resource_aws_codedeploy_app_test.go +++ b/builtin/providers/aws/resource_aws_codedeploy_app_test.go @@ -41,7 +41,7 @@ func testAccCheckAWSCodeDeployAppDestroy(s *terraform.State) error { } resp, err := conn.GetApplication(&codedeploy.GetApplicationInput{ - ApplicationName: aws.String(rs.Primary.ID), + ApplicationName: aws.String(rs.Primary.Attributes["name"]), }) if err == nil { diff --git a/builtin/providers/aws/resource_aws_codedeploy_deployment_group_test.go b/builtin/providers/aws/resource_aws_codedeploy_deployment_group_test.go index 3b873fe3bafe..fa97ca4cc68f 100644 --- a/builtin/providers/aws/resource_aws_codedeploy_deployment_group_test.go +++ b/builtin/providers/aws/resource_aws_codedeploy_deployment_group_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/codedeploy" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -45,6 +46,10 @@ func testAccCheckAWSCodeDeployDeploymentGroupDestroy(s *terraform.State) error { DeploymentGroupName: aws.String(rs.Primary.Attributes["deployment_group_name"]), }) + if ae, ok := err.(awserr.Error); ok && ae.Code() == "ApplicationDoesNotExistException" { + continue + } + if err == nil { if resp.DeploymentGroupInfo.DeploymentGroupName != nil { return fmt.Errorf("CodeDeploy deployment group still exists:\n%#v", *resp.DeploymentGroupInfo.DeploymentGroupName) diff --git a/builtin/providers/aws/resource_aws_customer_gateway_test.go b/builtin/providers/aws/resource_aws_customer_gateway_test.go index 9e3daec6d046..055e9054c1e5 100644 --- a/builtin/providers/aws/resource_aws_customer_gateway_test.go +++ b/builtin/providers/aws/resource_aws_customer_gateway_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" @@ -46,8 +47,33 @@ func TestAccAWSCustomerGateway_basic(t *testing.T) { } func testAccCheckCustomerGatewayDestroy(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_customer_gatewah" { + continue + } + + gatewayFilter := &ec2.Filter{ + Name: aws.String("customer-gateway-id"), + Values: []*string{aws.String(rs.Primary.ID)}, + } + + resp, err := conn.DescribeCustomerGateways(&ec2.DescribeCustomerGatewaysInput{ + Filters: []*ec2.Filter{gatewayFilter}, + }) + + if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidCustomerGatewayID.NotFound" { + continue + } + + if err == nil { + if len(resp.CustomerGateways) > 0 { + return fmt.Errorf("Customer gateway still exists: %v", resp.CustomerGateways) + } + } + + return err } return nil diff --git a/builtin/providers/aws/resource_aws_db_instance_test.go b/builtin/providers/aws/resource_aws_db_instance_test.go index 17e19227186a..6142281d0053 100644 --- a/builtin/providers/aws/resource_aws_db_instance_test.go +++ b/builtin/providers/aws/resource_aws_db_instance_test.go @@ -120,6 +120,10 @@ func testAccCheckAWSDBInstanceDestroy(s *terraform.State) error { DBInstanceIdentifier: aws.String(rs.Primary.ID), }) + if ae, ok := err.(awserr.Error); ok && ae.Code() == "DBInstanceNotFound" { + continue + } + if err == nil { if len(resp.DBInstances) != 0 && *resp.DBInstances[0].DBInstanceIdentifier == rs.Primary.ID { diff --git a/builtin/providers/aws/resource_aws_vpc_dhcp_options_test.go b/builtin/providers/aws/resource_aws_vpc_dhcp_options_test.go index 7ff15a5fa947..baa86f7d7d96 100644 --- a/builtin/providers/aws/resource_aws_vpc_dhcp_options_test.go +++ b/builtin/providers/aws/resource_aws_vpc_dhcp_options_test.go @@ -50,9 +50,12 @@ func testAccCheckDHCPOptionsDestroy(s *terraform.State) error { aws.String(rs.Primary.ID), }, }) + if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidDhcpOptionID.NotFound" { + continue + } if err == nil { if len(resp.DhcpOptions) > 0 { - return fmt.Errorf("still exist.") + return fmt.Errorf("still exists") } return nil