diff --git a/aws/resource_aws_kinesis_stream.go b/aws/resource_aws_kinesis_stream.go index a0a2eb31122..c86e1379357 100644 --- a/aws/resource_aws_kinesis_stream.go +++ b/aws/resource_aws_kinesis_stream.go @@ -57,6 +57,12 @@ func resourceAwsKinesisStream() *schema.Resource { Set: schema.HashString, }, + "enforce_consumer_deletion": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + "encryption_type": { Type: schema.TypeString, Optional: true, @@ -204,7 +210,8 @@ func resourceAwsKinesisStreamDelete(d *schema.ResourceData, meta interface{}) er sn := d.Get("name").(string) _, err := conn.DeleteStream(&kinesis.DeleteStreamInput{ - StreamName: aws.String(sn), + StreamName: aws.String(sn), + EnforceConsumerDeletion: aws.Bool(d.Get("enforce_consumer_deletion").(bool)), }) if err != nil { return err diff --git a/aws/resource_aws_kinesis_stream_test.go b/aws/resource_aws_kinesis_stream_test.go index f508192479d..ce28806f7d9 100644 --- a/aws/resource_aws_kinesis_stream_test.go +++ b/aws/resource_aws_kinesis_stream_test.go @@ -143,10 +143,11 @@ func TestAccAWSKinesisStream_importBasic(t *testing.T) { }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, - ImportStateId: streamName, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateId: streamName, + ImportStateVerifyIgnore: []string{"enforce_consumer_deletion"}, }, }, }) @@ -282,6 +283,28 @@ func TestAccAWSKinesisStream_shardLevelMetrics(t *testing.T) { }) } +func TestAccAWSKinesisStream_enforceConsumerDeletion(t *testing.T) { + var stream kinesis.StreamDescription + + rInt := acctest.RandInt() + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckKinesisStreamDestroy, + Steps: []resource.TestStep{ + { + Config: testAccKinesisStreamConfigWithEnforceConsumerDeletion(rInt), + Check: resource.ComposeTestCheckFunc( + testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream", &stream), + testAccCheckAWSKinesisStreamAttributes(&stream), + testAccAWSKinesisStreamRegisterStreamConsumer(&stream, fmt.Sprintf("tf-test-%d", rInt)), + ), + }, + }, + }) +} + func TestAccAWSKinesisStream_Tags(t *testing.T) { var stream kinesis.StreamDescription resourceName := "aws_kinesis_stream.test" @@ -381,6 +404,21 @@ func testAccCheckKinesisStreamDestroy(s *terraform.State) error { return nil } +func testAccAWSKinesisStreamRegisterStreamConsumer(stream *kinesis.StreamDescription, rStr string) resource.TestCheckFunc { + return func(s *terraform.State) error { + conn := testAccProvider.Meta().(*AWSClient).kinesisconn + + if _, err := conn.RegisterStreamConsumer(&kinesis.RegisterStreamConsumerInput{ + ConsumerName: aws.String(rStr), + StreamARN: stream.StreamARN, + }); err != nil { + return err + } + + return nil + } +} + func testAccKinesisStreamConfig(rInt int) string { return fmt.Sprintf(` resource "aws_kinesis_stream" "test_stream" { @@ -537,3 +575,16 @@ resource "aws_kinesis_stream" "test" { } }`, rInt, tagPairs) } + +func testAccKinesisStreamConfigWithEnforceConsumerDeletion(rInt int) string { + return fmt.Sprintf(` +resource "aws_kinesis_stream" "test_stream" { + name = "terraform-kinesis-test-%d" + shard_count = 2 + enforce_consumer_deletion = true + + tags = { + Name = "tf-test" + } +}`, rInt) +} diff --git a/website/docs/r/kinesis_stream.html.markdown b/website/docs/r/kinesis_stream.html.markdown index 1fb2b804f96..b18656a2ba1 100644 --- a/website/docs/r/kinesis_stream.html.markdown +++ b/website/docs/r/kinesis_stream.html.markdown @@ -43,6 +43,7 @@ Amazon has guidlines for specifying the Stream size that should be referenced when creating a Kinesis stream. See [Amazon Kinesis Streams][2] for more. * `retention_period` - (Optional) Length of time data records are accessible after they are added to the stream. The maximum value of a stream's retention period is 168 hours. Minimum value is 24. Default is 24. * `shard_level_metrics` - (Optional) A list of shard-level CloudWatch metrics which can be enabled for the stream. See [Monitoring with CloudWatch][3] for more. Note that the value ALL should not be used; instead you should provide an explicit list of metrics you wish to enable. +* `enforce_consumer_deletion` - (Optional) A boolean that indicates all registered consumers should be deregistered from the stream so that the stream can be destroyed without error. The default value is `false`. * `encryption_type` - (Optional) The encryption type to use. The only acceptable values are `NONE` or `KMS`. The default value is `NONE`. * `kms_key_id` - (Optional) The GUID for the customer-managed KMS key to use for encryption. You can also use a Kinesis-owned master key by specifying the alias `alias/aws/kinesis`. * `tags` - (Optional) A mapping of tags to assign to the resource.