Skip to content

Commit

Permalink
Add retry logic to s3_bucket to prevent OperationAborted errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Radek Simko committed Feb 17, 2016
1 parent b7a63c1 commit 8481625
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion builtin/providers/aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,20 @@ func resourceAwsS3BucketCreate(d *schema.ResourceData, meta interface{}) error {
}
}

_, err := s3conn.CreateBucket(req)
err := resource.Retry(5*time.Minute, func() error {
log.Printf("[DEBUG] Trying to create new S3 bucket: %q", bucket)
_, err := s3conn.CreateBucket(req)
if awsErr, ok := err.(awserr.Error); ok {
if awsErr.Code() == "OperationAborted" {
log.Printf("[WARN] Got an error while trying to create S3 bucket %s: %s", bucket, err)
return fmt.Errorf("[WARN] Error creating S3 bucket %s, retrying: %s",
bucket, err)
}
return resource.RetryError{Err: err}
}
return nil
})

if err != nil {
return fmt.Errorf("Error creating S3 bucket: %s", err)
}
Expand Down

0 comments on commit 8481625

Please sign in to comment.