Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kinesis concurrent CreateStream backoff #1339

Merged
merged 2 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions aws/resource_aws_kinesis_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,24 @@ func resourceAwsKinesisStreamCreate(d *schema.ResourceData, meta interface{}) er
StreamName: aws.String(sn),
}

_, err := conn.CreateStream(createOpts)
if err != nil {
if awsErr, ok := err.(awserr.Error); ok {
return fmt.Errorf("[WARN] Error creating Kinesis Stream: \"%s\", code: \"%s\"", awsErr.Message(), awsErr.Code())
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.CreateStream(createOpts)
if isAWSErr(err, "LimitExceededException", "simultaneously be in CREATING or DELETING") {
return resource.RetryableError(err)
}
return err
// AWS (un)helpfully raises LimitExceededException
// rather than ThrottlingException here
if isAWSErr(err, "LimitExceededException", "Rate exceeded for stream") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
})

if err != nil {
return fmt.Errorf("Unable to create stream: %s", err)
}

// No error, wait for ACTIVE state
stateConf := &resource.StateChangeConf{
Pending: []string{"CREATING"},
Target: []string{"ACTIVE"},
Expand Down
51 changes: 51 additions & 0 deletions aws/resource_aws_kinesis_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,45 @@ func TestAccAWSKinesisStream_basic(t *testing.T) {
})
}

func TestAccAWSKinesisStream_createMultipleConcurrentStreams(t *testing.T) {
var stream kinesis.StreamDescription

rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckKinesisStreamDestroy,
Steps: []resource.TestStep{
{
Config: testAccKinesisStreamConfigConcurrent(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.0", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.1", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.2", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.3", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.4", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.5", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.6", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.7", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.8", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.9", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.10", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.11", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.12", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.13", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.14", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.15", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.16", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.17", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.18", &stream),
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream.19", &stream),
),
},
},
})
}

func TestAccAWSKinesisStream_encryptionWithoutKmsKeyThrowsError(t *testing.T) {
rInt := acctest.RandInt()

Expand Down Expand Up @@ -324,6 +363,18 @@ resource "aws_kinesis_stream" "test_stream" {
}`, rInt)
}

func testAccKinesisStreamConfigConcurrent(rInt int) string {
return fmt.Sprintf(`
resource "aws_kinesis_stream" "test_stream" {
count = 20
name = "terraform-kinesis-test-%d-${count.index}"
shard_count = 2
tags {
Name = "tf-test"
}
}`, rInt)
}

func testAccKinesisStreamConfigWithEncryptionAndNoKmsKey(rInt int) string {
return fmt.Sprintf(`
resource "aws_kinesis_stream" "test_stream" {
Expand Down