Skip to content

Commit

Permalink
add waituntilbucketexists to avoid race in s3 bucket creation calls
Browse files Browse the repository at this point in the history
issue: [hashicorp#877]
  • Loading branch information
xchapter7x committed Aug 10, 2017
1 parent 1340937 commit 9881a85
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions aws/resource_aws_s3_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aws
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"
"net/url"
Expand Down Expand Up @@ -464,6 +465,22 @@ func resourceAwsS3BucketCreate(d *schema.ResourceData, meta interface{}) error {
// Assign the bucket name as the resource ID
d.SetId(bucket)

errChannel := make(chan error)
go func() {
err := s3conn.WaitUntilBucketExists(&s3.HeadBucketInput{
Bucket: aws.String(bucket),
})
errChannel <- err
}()

select {
case err := <-errChannel:
if err != nil {
return fmt.Errorf("Error waiting for S3 Bucket creation: ", err)
}
case <-time.After(60):
return errors.New("S3 bucket creation timed out")
}
return resourceAwsS3BucketUpdate(d, meta)
}

Expand Down

0 comments on commit 9881a85

Please sign in to comment.