From 450cbba11a47503a7ecfa20c34e2f6b55b67e403 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 11 Jul 2014 12:57:23 -0700 Subject: [PATCH] providers/aws: route table should delete any associations --- .../providers/aws/resource_aws_route_table.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/builtin/providers/aws/resource_aws_route_table.go b/builtin/providers/aws/resource_aws_route_table.go index 66f815d3a..edc5d2d77 100644 --- a/builtin/providers/aws/resource_aws_route_table.go +++ b/builtin/providers/aws/resource_aws_route_table.go @@ -132,6 +132,25 @@ func resource_aws_route_table_destroy( p := meta.(*ResourceProvider) ec2conn := p.ec2conn + // First request the routing table since we'll have to disassociate + // all the subnets first. + rtRaw, _, err := RouteTableStateRefreshFunc(ec2conn, s.ID)() + if err != nil { + return err + } + if rtRaw == nil { + return nil + } + rt := rtRaw.(*ec2.RouteTable) + + // Do all the disassociations + for _, a := range rt.Associations { + if _, err := ec2conn.DisassociateRouteTable(a.AssociationId); err != nil { + return err + } + } + + // Delete the route table log.Printf("[INFO] Deleting Route Table: %s", s.ID) if _, err := ec2conn.DeleteRouteTable(s.ID); err != nil { ec2err, ok := err.(*ec2.Error)