From e0bc61d414fa502cc7817e68e5d5f0116a422ccb Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 11 Jul 2014 13:10:09 -0700 Subject: [PATCH] providers/aws: route table association tests --- .../providers/aws/resource_aws_route_table.go | 1 + .../resource_aws_route_table_association.go | 6 ++++ ...source_aws_route_table_association_test.go | 30 ++++++++++++++++++- builtin/providers/aws/resource_aws_subnet.go | 4 +++ 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_route_table.go b/builtin/providers/aws/resource_aws_route_table.go index edc5d2d77..12a0fffe1 100644 --- a/builtin/providers/aws/resource_aws_route_table.go +++ b/builtin/providers/aws/resource_aws_route_table.go @@ -145,6 +145,7 @@ func resource_aws_route_table_destroy( // Do all the disassociations for _, a := range rt.Associations { + log.Printf("[INFO] Disassociating association: %s", a.AssociationId) if _, err := ec2conn.DisassociateRouteTable(a.AssociationId); err != nil { return err } diff --git a/builtin/providers/aws/resource_aws_route_table_association.go b/builtin/providers/aws/resource_aws_route_table_association.go index f872ddf76..828508262 100644 --- a/builtin/providers/aws/resource_aws_route_table_association.go +++ b/builtin/providers/aws/resource_aws_route_table_association.go @@ -55,6 +55,12 @@ func resource_aws_route_table_association_update( rs.ID, rs.Attributes["route_table_id"]) if err != nil { + ec2err, ok := err.(*ec2.Error) + if ok && ec2err.Code == "InvalidAssociationID.NotFound" { + // Not found, so just create a new one + return resource_aws_route_table_association_create(s, d, meta) + } + return s, err } diff --git a/builtin/providers/aws/resource_aws_route_table_association_test.go b/builtin/providers/aws/resource_aws_route_table_association_test.go index 944c83ba4..52e37b07e 100644 --- a/builtin/providers/aws/resource_aws_route_table_association_test.go +++ b/builtin/providers/aws/resource_aws_route_table_association_test.go @@ -10,7 +10,7 @@ import ( ) func TestAccAWSRouteTableAssociation(t *testing.T) { - var v ec2.RouteTable + var v, v2 ec2.RouteTable resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -24,6 +24,14 @@ func TestAccAWSRouteTableAssociation(t *testing.T) { "aws_route_table_association.foo", &v), ), }, + + resource.TestStep{ + Config: testAccRouteTableAssociationConfigChange, + Check: resource.ComposeTestCheckFunc( + testAccCheckRouteTableAssociationExists( + "aws_route_table_association.foo", &v2), + ), + }, }, }) } @@ -112,3 +120,23 @@ resource "aws_route_table_association" "foo" { subnet_id = "${aws_subnet.foo.id}" } ` + +const testAccRouteTableAssociationConfigChange = ` +resource "aws_vpc" "foo" { + cidr_block = "10.1.0.0/16" +} + +resource "aws_subnet" "foo" { + vpc_id = "${aws_vpc.foo.id}" + cidr_block = "10.1.1.0/24" +} + +resource "aws_route_table" "bar" { + vpc_id = "${aws_vpc.foo.id}" +} + +resource "aws_route_table_association" "foo" { + route_table_id = "${aws_route_table.bar.id}" + subnet_id = "${aws_subnet.foo.id}" +} +` diff --git a/builtin/providers/aws/resource_aws_subnet.go b/builtin/providers/aws/resource_aws_subnet.go index 4e0ef5597..327666814 100644 --- a/builtin/providers/aws/resource_aws_subnet.go +++ b/builtin/providers/aws/resource_aws_subnet.go @@ -131,6 +131,10 @@ func resource_aws_subnet_diff( "cidr_block": diff.AttrTypeCreate, "vpc_id": diff.AttrTypeCreate, }, + + ComputedAttrs: []string{ + "availability_zone", + }, } return b.Diff(s, c)