From 627efa21f461f10352a092f9c3441fb8c83cf8e8 Mon Sep 17 00:00:00 2001 From: Clint Date: Tue, 14 Jun 2016 15:39:52 -0500 Subject: [PATCH] provider/aws: Retry RouteTable Route/Assocation creation (#7156) * provider/aws: Retry RouteTable Assocation creation * provider/aws: retry route creation * remove extra string check --- .../providers/aws/resource_aws_route_table.go | 14 ++++++++++++- .../resource_aws_route_table_association.go | 20 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_route_table.go b/builtin/providers/aws/resource_aws_route_table.go index 218c39bbc..1c91d916e 100644 --- a/builtin/providers/aws/resource_aws_route_table.go +++ b/builtin/providers/aws/resource_aws_route_table.go @@ -301,7 +301,19 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error } log.Printf("[INFO] Creating route for %s: %#v", d.Id(), opts) - if _, err := conn.CreateRoute(&opts); err != nil { + err := resource.Retry(1*time.Minute, func() *resource.RetryError { + _, err := conn.CreateRoute(&opts) + if err != nil { + if awsErr, ok := err.(awserr.Error); ok { + if awsErr.Code() == "InvalidRouteTableID.NotFound" { + return resource.RetryableError(awsErr) + } + } + return resource.NonRetryableError(err) + } + return nil + }) + if 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 c6d68786a..d68107859 100644 --- a/builtin/providers/aws/resource_aws_route_table_association.go +++ b/builtin/providers/aws/resource_aws_route_table_association.go @@ -3,10 +3,12 @@ package aws import ( "fmt" "log" + "time" "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" "github.com/hashicorp/terraform/helper/schema" ) @@ -40,11 +42,25 @@ func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interfa d.Get("subnet_id").(string), d.Get("route_table_id").(string)) - resp, err := conn.AssociateRouteTable(&ec2.AssociateRouteTableInput{ + associationOpts := ec2.AssociateRouteTableInput{ RouteTableId: aws.String(d.Get("route_table_id").(string)), SubnetId: aws.String(d.Get("subnet_id").(string)), - }) + } + var resp *ec2.AssociateRouteTableOutput + var err error + err = resource.Retry(2*time.Minute, func() *resource.RetryError { + resp, err = conn.AssociateRouteTable(&associationOpts) + if err != nil { + if awsErr, ok := err.(awserr.Error); ok { + if awsErr.Code() == "InvalidRouteTableID.NotFound" { + return resource.RetryableError(awsErr) + } + } + return resource.NonRetryableError(err) + } + return nil + }) if err != nil { return err }