Skip to content

Commit

Permalink
resource/aws_kinesis_stream: Retry deletion on LimitExceededException (
Browse files Browse the repository at this point in the history
…#3108)

* resource/aws_kinesis_stream: Retry deletion on LimitExceededException

* resource/aws_kinesis_stream: Move retryers to SDK
  • Loading branch information
radeksimko authored Feb 9, 2018
1 parent 5d92033 commit ede5def
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 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
16 changes: 2 additions & 14 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, "LimitExceededException", "simultaneously be in CREATING or DELETING") {
return resource.RetryableError(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)
})

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

_, err := conn.DeleteStream(&kinesis.DeleteStreamInput{
StreamName: aws.String(sn),
})

if err != nil {
return err
}
Expand Down

0 comments on commit ede5def

Please sign in to comment.