Skip to content

Commit

Permalink
resource/aws_kinesis_stream: Move retryers to SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Feb 9, 2018
1 parent 486dcc5 commit ee415f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
13 changes: 13 additions & 0 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,19 @@ func (c *Config) Client() (interface{}, error) {
}
})

client.kinesisconn.Handlers.Retry.PushBack(func(r *request.Request) {
if r.Operation.Name == "CreateStream" {
if isAWSErr(r.Error, kinesis.ErrCodeLimitExceededException, "simultaneously be in CREATING or DELETING") {
r.Retryable = aws.Bool(true)
}
}
if r.Operation.Name == "CreateStream" || r.Operation.Name == "DeleteStream" {
if isAWSErr(r.Error, kinesis.ErrCodeLimitExceededException, "Rate exceeded for stream") {
r.Retryable = aws.Bool(true)
}
}
})

return &client, nil
}

Expand Down
28 changes: 3 additions & 25 deletions aws/resource_aws_kinesis_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,7 @@ func resourceAwsKinesisStreamCreate(d *schema.ResourceData, meta interface{}) er
StreamName: aws.String(sn),
}

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.CreateStream(createOpts)
if isAWSErr(err, kinesis.ErrCodeLimitExceededException, "simultaneously be in CREATING or DELETING") {
return resource.RetryableError(err)
}
// AWS (un)helpfully raises LimitExceededException
// rather than ThrottlingException here
if isAWSErr(err, kinesis.ErrCodeLimitExceededException, "Rate exceeded for stream") {
return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
})

_, err := conn.CreateStream(createOpts)
if err != nil {
return fmt.Errorf("Unable to create stream: %s", err)
}
Expand Down Expand Up @@ -222,18 +210,8 @@ func resourceAwsKinesisStreamDelete(d *schema.ResourceData, meta interface{}) er
conn := meta.(*AWSClient).kinesisconn
sn := d.Get("name").(string)

err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteStream(&kinesis.DeleteStreamInput{
StreamName: aws.String(sn),
})
if err != nil {
if isAWSErr(err, kinesis.ErrCodeLimitExceededException, "Rate exceeded for stream") {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
}
return nil
_, err := conn.DeleteStream(&kinesis.DeleteStreamInput{
StreamName: aws.String(sn),
})
if err != nil {
return err
Expand Down

0 comments on commit ee415f4

Please sign in to comment.