Skip to content

Commit

Permalink
Merge pull request #9797 from terraform-providers/rfd-retry-routes
Browse files Browse the repository at this point in the history
Final retries for routes
  • Loading branch information
ryndaniels authored Aug 20, 2019
2 parents d616724 + 146bbae commit c7ab4e3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
32 changes: 21 additions & 11 deletions aws/resource_aws_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {

return nil
})
if isResourceTimeoutError(err) {
_, err = conn.CreateRoute(createOpts)
}
if err != nil {
return fmt.Errorf("Error creating route: %s", err)
}
Expand All @@ -280,6 +283,9 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
route, err = resourceAwsRouteFindRoute(conn, d.Get("route_table_id").(string), v.(string), "")
return resource.RetryableError(err)
})
if isResourceTimeoutError(err) {
route, err = resourceAwsRouteFindRoute(conn, d.Get("route_table_id").(string), v.(string), "")
}
if err != nil {
return fmt.Errorf("Error finding route after creating it: %s", err)
}
Expand All @@ -290,6 +296,9 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
route, err = resourceAwsRouteFindRoute(conn, d.Get("route_table_id").(string), "", v.(string))
return resource.RetryableError(err)
})
if isResourceTimeoutError(err) {
route, err = resourceAwsRouteFindRoute(conn, d.Get("route_table_id").(string), "", v.(string))
}
if err != nil {
return fmt.Errorf("Error finding route after creating it: %s", err)
}
Expand Down Expand Up @@ -440,29 +449,30 @@ func resourceAwsRouteDelete(d *schema.ResourceData, meta interface{}) error {
}
log.Printf("[DEBUG] Route delete opts: %s", deleteOpts)

var err error = resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
var resp *ec2.DeleteRouteOutput
err := resource.Retry(d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
log.Printf("[DEBUG] Trying to delete route with opts %s", deleteOpts)
resp, err := conn.DeleteRoute(deleteOpts)
var err error
resp, err = conn.DeleteRoute(deleteOpts)
log.Printf("[DEBUG] Route delete result: %s", resp)

if err == nil {
return nil
}

ec2err, ok := err.(awserr.Error)
if !ok {
return resource.NonRetryableError(err)
}
if ec2err.Code() == "InvalidParameterException" {
log.Printf("[DEBUG] Trying to delete route again: %q",
ec2err.Message())
if isAWSErr(err, "InvalidParameterException", "") {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
})

return err
if isResourceTimeoutError(err) {
resp, err = conn.DeleteRoute(deleteOpts)
}
if err != nil {
return fmt.Errorf("Error deleting route: %s", err)
}
return nil
}

func resourceAwsRouteExists(d *schema.ResourceData, meta interface{}) (bool, error) {
Expand Down
5 changes: 4 additions & 1 deletion aws/resource_aws_route_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,11 @@ func resourceAwsRouteTableUpdate(d *schema.ResourceData, meta interface{}) error
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.CreateRoute(&opts)
}
if err != nil {
return err
return fmt.Errorf("Error creating route: %s", err)
}

routes.Add(route)
Expand Down
9 changes: 7 additions & 2 deletions aws/resource_aws_route_table_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interfa
}

var associationID string
var resp *ec2.AssociateRouteTableOutput
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.AssociateRouteTable(&associationOpts)
var err error
resp, err = conn.AssociateRouteTable(&associationOpts)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "InvalidRouteTableID.NotFound" {
Expand All @@ -64,8 +66,11 @@ func resourceAwsRouteTableAssociationCreate(d *schema.ResourceData, meta interfa
associationID = *resp.AssociationId
return nil
})
if isResourceTimeoutError(err) {
resp, err = conn.AssociateRouteTable(&associationOpts)
}
if err != nil {
return err
return fmt.Errorf("Error creating route table association: %s", err)
}

// Set the ID and return
Expand Down

0 comments on commit c7ab4e3

Please sign in to comment.