Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_kinesis_stream: Add Support enforce_consumer_deletion attribute #8682

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The whitespace here looks like tabs instead of spaces.

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