provider/aws: Retry RouteTable Route/Assocation creation (#7156)

* provider/aws: Retry RouteTable Assocation creation

* provider/aws: retry route creation

* remove extra string check
This commit is contained in:
Clint 2016-06-14 15:39:52 -05:00 committed by GitHub
parent 4796e27d1a
commit 627efa21f4
2 changed files with 31 additions and 3 deletions

View File

@ -301,7 +301,19 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
} }
log.Printf("[INFO] Creating route for %s: %#v", d.Id(), opts) 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 return err
} }

View File

@ -3,10 +3,12 @@ package aws
import ( import (
"fmt" "fmt"
"log" "log"
"time"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -40,11 +42,25 @@ func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interfa
d.Get("subnet_id").(string), d.Get("subnet_id").(string),
d.Get("route_table_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)), RouteTableId: aws.String(d.Get("route_table_id").(string)),
SubnetId: aws.String(d.Get("subnet_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 { if err != nil {
return err return err
} }