From ae8627f92a8d74e6f3d293f2f8e86fd29844f4dc Mon Sep 17 00:00:00 2001 From: Maxime Bury Date: Tue, 1 Mar 2016 10:46:39 -0800 Subject: [PATCH] Report the correct number of shards --- .../providers/aws/resource_aws_kinesis_stream.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_kinesis_stream.go b/builtin/providers/aws/resource_aws_kinesis_stream.go index 5fe18b7cc..1d70d8476 100644 --- a/builtin/providers/aws/resource_aws_kinesis_stream.go +++ b/builtin/providers/aws/resource_aws_kinesis_stream.go @@ -247,7 +247,7 @@ func readKinesisStreamState(conn *kinesis.Kinesis, sn string) (kinesisStreamStat err := conn.DescribeStreamPages(describeOpts, func(page *kinesis.DescribeStreamOutput, last bool) (shouldContinue bool) { state.arn = aws.StringValue(page.StreamDescription.StreamARN) state.status = aws.StringValue(page.StreamDescription.StreamStatus) - state.shardCount += len(page.StreamDescription.Shards) + state.shardCount += len(openShards(page.StreamDescription.Shards)) state.retentionPeriod = aws.Int64Value(page.StreamDescription.RetentionPeriodHours) return !last }) @@ -270,3 +270,15 @@ func streamStateRefreshFunc(conn *kinesis.Kinesis, sn string) resource.StateRefr return state, state.status, nil } } + +// See http://docs.aws.amazon.com/kinesis/latest/dev/kinesis-using-sdk-java-resharding-merge.html +func openShards(shards []*kinesis.Shard) []*kinesis.Shard { + var open []*kinesis.Shard + for _, s := range shards { + if s.SequenceNumberRange.EndingSequenceNumber == nil { + open = append(open, s) + } + } + + return open +}