Skip to content

Commit

Permalink
Merge pull request #8994 from terraform-providers/rfd-retry-rds
Browse files Browse the repository at this point in the history
Final retries for RDS cluster functions
  • Loading branch information
ryndaniels authored Jun 18, 2019
2 parents 5094774 + 19a239a commit a30e902
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
19 changes: 18 additions & 1 deletion aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.RestoreDBClusterFromSnapshot(&opts)
}
if err != nil {
return fmt.Errorf("Error creating RDS Cluster: %s", err)
}
Expand Down Expand Up @@ -602,6 +605,9 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
}
return nil
})
if isResourceTimeoutError(err) {
resp, err = conn.CreateDBCluster(createOpts)
}
if err != nil {
return fmt.Errorf("error creating RDS cluster: %s", err)
}
Expand Down Expand Up @@ -695,8 +701,10 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error

log.Printf("[DEBUG] RDS Cluster restore options: %s", createOpts)
// Retry for IAM/S3 eventual consistency
var resp *rds.RestoreDBClusterFromS3Output
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.RestoreDBClusterFromS3(createOpts)
var err error
resp, err = conn.RestoreDBClusterFromS3(createOpts)
if err != nil {
// InvalidParameterValue: Files from the specified Amazon S3 bucket cannot be downloaded.
// Make sure that you have created an AWS Identity and Access Management (IAM) role that lets Amazon RDS access Amazon S3 for you.
Expand All @@ -714,6 +722,9 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
log.Printf("[DEBUG]: RDS Cluster create response: %s", resp)
return nil
})
if isResourceTimeoutError(err) {
resp, err = conn.RestoreDBClusterFromS3(createOpts)
}

if err != nil {
log.Printf("[ERROR] Error creating RDS Cluster: %s", err)
Expand Down Expand Up @@ -837,6 +848,9 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
}
return nil
})
if isResourceTimeoutError(err) {
resp, err = conn.CreateDBCluster(createOpts)
}
if err != nil {
return fmt.Errorf("error creating RDS cluster: %s", err)
}
Expand Down Expand Up @@ -1128,6 +1142,9 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.ModifyDBCluster(req)
}
if err != nil {
return fmt.Errorf("Failed to modify RDS Cluster (%s): %s", d.Id(), err)
}
Expand Down
6 changes: 6 additions & 0 deletions aws/resource_aws_rds_cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ func resourceAwsRDSClusterInstanceCreate(d *schema.ResourceData, meta interface{
}
return nil
})
if isResourceTimeoutError(err) {
resp, err = conn.CreateDBInstance(createOpts)
}
if err != nil {
return fmt.Errorf("error creating RDS DB Instance: %s", err)
}
Expand Down Expand Up @@ -500,6 +503,9 @@ func resourceAwsRDSClusterInstanceUpdate(d *schema.ResourceData, meta interface{
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.ModifyDBInstance(req)
}
if err != nil {
return fmt.Errorf("Error modifying DB Instance %s: %s", d.Id(), err)
}
Expand Down
4 changes: 4 additions & 0 deletions aws/resource_aws_rds_global_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ func resourceAwsRDSGlobalClusterDelete(d *schema.ResourceData, meta interface{})
return nil
})

if isResourceTimeoutError(err) {
_, err = conn.DeleteGlobalCluster(input)
}

if isAWSErr(err, rds.ErrCodeGlobalClusterNotFoundFault, "") {
return nil
}
Expand Down

0 comments on commit a30e902

Please sign in to comment.