Skip to content

Commit

Permalink
Merge pull request #4371 from terraform-providers/b-aws_rds_cluster-i…
Browse files Browse the repository at this point in the history
…am-retries

resource/aws_rds_cluster: Add retries for IAM eventual consistency
  • Loading branch information
bflad authored Apr 27, 2018
2 parents 6ef2184 + ec4ab4a commit 2259792
Showing 1 changed file with 40 additions and 9 deletions.
49 changes: 40 additions & 9 deletions aws/resource_aws_rds_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,16 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[DEBUG] RDS Cluster restore from snapshot configuration: %s", opts)
_, err := conn.RestoreDBClusterFromSnapshot(&opts)
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
_, err := conn.RestoreDBClusterFromSnapshot(&opts)
if err != nil {
if isAWSErr(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return fmt.Errorf("Error creating RDS Cluster: %s", err)
}
Expand Down Expand Up @@ -424,10 +433,20 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[DEBUG] Create RDS Cluster as read replica: %s", createOpts)
resp, err := conn.CreateDBCluster(createOpts)
var resp *rds.CreateDBClusterOutput
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
resp, err = conn.CreateDBCluster(createOpts)
if err != nil {
if isAWSErr(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
log.Printf("[ERROR] Error creating RDS Cluster: %s", err)
return err
return fmt.Errorf("error creating RDS cluster: %s", err)
}

log.Printf("[DEBUG]: RDS Cluster create response: %s", resp)
Expand Down Expand Up @@ -499,10 +518,20 @@ func resourceAwsRDSClusterCreate(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[DEBUG] RDS Cluster create options: %s", createOpts)
resp, err := conn.CreateDBCluster(createOpts)
var resp *rds.CreateDBClusterOutput
err := resource.Retry(1*time.Minute, func() *resource.RetryError {
var err error
resp, err = conn.CreateDBCluster(createOpts)
if err != nil {
if isAWSErr(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
log.Printf("[ERROR] Error creating RDS Cluster: %s", err)
return err
return fmt.Errorf("error creating RDS cluster: %s", err)
}

log.Printf("[DEBUG]: RDS Cluster create response: %s", resp)
Expand Down Expand Up @@ -704,8 +733,10 @@ func resourceAwsRDSClusterUpdate(d *schema.ResourceData, meta interface{}) error
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.ModifyDBCluster(req)
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && awsErr.Code() == rds.ErrCodeInvalidDBClusterStateFault {
if isAWSErr(err, "InvalidParameterValue", "IAM role ARN value is invalid or does not include the required permissions") {
return resource.RetryableError(err)
}
if isAWSErr(err, rds.ErrCodeInvalidDBClusterStateFault, "") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
Expand Down

0 comments on commit 2259792

Please sign in to comment.