Use resource.Retry for route creation and deletion (#6225)
* Use resource.Retry for route creation and deletion * Remove uneeded out var in resource_aws_route.go
This commit is contained in:
parent
6ebac8403d
commit
e108275331
|
@ -4,10 +4,13 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"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/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -152,7 +155,26 @@ func resourceAwsRouteCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
log.Printf("[DEBUG] Route create config: %s", createOpts)
|
log.Printf("[DEBUG] Route create config: %s", createOpts)
|
||||||
|
|
||||||
// Create the route
|
// Create the route
|
||||||
_, err := conn.CreateRoute(createOpts)
|
var err error
|
||||||
|
|
||||||
|
err = resource.Retry(2*time.Minute, func() *resource.RetryError {
|
||||||
|
_, err = conn.CreateRoute(createOpts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
ec2err, ok := err.(awserr.Error)
|
||||||
|
if !ok {
|
||||||
|
return resource.NonRetryableError(err)
|
||||||
|
}
|
||||||
|
if ec2err.Code() == "InvalidParameterException" {
|
||||||
|
log.Printf("[DEBUG] Trying to create route again: %q", ec2err.Message())
|
||||||
|
return resource.RetryableError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resource.NonRetryableError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error creating route: %s", err)
|
return fmt.Errorf("Error creating route: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -269,8 +291,29 @@ func resourceAwsRouteDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] Route delete opts: %s", deleteOpts)
|
log.Printf("[DEBUG] Route delete opts: %s", deleteOpts)
|
||||||
|
|
||||||
resp, err := conn.DeleteRoute(deleteOpts)
|
var err error
|
||||||
log.Printf("[DEBUG] Route delete result: %s", resp)
|
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
|
||||||
|
log.Printf("[DEBUG] Trying to delete route with opts %s", deleteOpts)
|
||||||
|
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())
|
||||||
|
return resource.RetryableError(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return resource.NonRetryableError(err)
|
||||||
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue