Skip to content

Commit

Permalink
r/aws_kinesis_stream: Add Support enforce_consumer_deletion attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
teraken0509 committed May 18, 2019
1 parent 238ace9 commit be79359
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
9 changes: 8 additions & 1 deletion aws/resource_aws_kinesis_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
59 changes: 55 additions & 4 deletions aws/resource_aws_kinesis_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
},
},
})
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}
1 change: 1 addition & 0 deletions website/docs/r/kinesis_stream.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit be79359

Please sign in to comment.