From b7e87bbf167f78082f26ab125e32d86bbe890fac Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Tue, 22 Dec 2015 09:02:01 -0600 Subject: [PATCH] provider/aws: fix CheckDestroy for main_route_table_association tests --- ...e_aws_main_route_table_association_test.go | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/builtin/providers/aws/resource_aws_main_route_table_association_test.go b/builtin/providers/aws/resource_aws_main_route_table_association_test.go index 49f2815d9d..191696ef2d 100644 --- a/builtin/providers/aws/resource_aws_main_route_table_association_test.go +++ b/builtin/providers/aws/resource_aws_main_route_table_association_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -39,8 +40,28 @@ func TestAccAWSMainRouteTableAssociation_basic(t *testing.T) { } func testAccCheckMainRouteTableAssociationDestroy(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_main_route_table_association" { + continue + } + + mainAssociation, err := findMainRouteTableAssociation( + conn, + rs.Primary.Attributes["vpc_id"], + ) + if err != nil { + // Verify the error is what we want + if ae, ok := err.(awserr.Error); ok && ae.Code() == "ApplicationDoesNotExistException" { + continue + } + return err + } + + if mainAssociation != nil { + return fmt.Errorf("still exists") + } } return nil