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

Added support for Kinesis Extended S3 Configuration Backup Mode #2987

Merged
merged 3 commits into from
Apr 4, 2018
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
37 changes: 32 additions & 5 deletions aws/resource_aws_kinesis_firehose_delivery_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ func flattenKinesisFirehoseDeliveryStream(d *schema.ResourceData, s *firehose.De
"role_arn": roleArn,
"compression_format": *destination.ExtendedS3DestinationDescription.CompressionFormat,
"prefix": *destination.ExtendedS3DestinationDescription.Prefix,
"s3_backup_mode": *destination.ExtendedS3DestinationDescription.S3BackupMode,
"cloudwatch_logging_options": flattenCloudwatchLoggingOptions(*destination.ExtendedS3DestinationDescription.CloudWatchLoggingOptions),
}

Expand All @@ -355,13 +356,13 @@ func flattenKinesisFirehoseDeliveryStream(d *schema.ResourceData, s *firehose.De
extendedS3Configuration["processing_configuration"] = flattenProcessingConfiguration(*v, roleArn)
}

if v := destination.ExtendedS3DestinationDescription.S3BackupDescription; v != nil {
extendedS3Configuration["s3_backup_configuration"] = flattenFirehoseS3Configuration(*v)
}

extendedS3ConfList := make([]map[string]interface{}, 1)
extendedS3ConfList[0] = extendedS3Configuration

err := d.Set("extended_s3_configuration", extendedS3ConfList)
if err != nil {
return err
}
d.Set("extended_s3_configuration", extendedS3ConfList)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep the err check when setting complex attributes (e.g. non-string)

}
d.Set("destination_id", *destination.DestinationId)
}
Expand Down Expand Up @@ -491,6 +492,22 @@ func resourceAwsKinesisFirehoseDeliveryStream() *schema.Resource {
Optional: true,
},

"s3_backup_mode": {
Type: schema.TypeString,
Optional: true,
Default: "Disabled",
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nitpick: Prefer usage of the SDK provided constant firehose.S3BackupModeDisabled

ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified with:

ValidateFunc: validation.StringInSlice([]string{
  firehose.S3BackupModeDisabled,
  firehose.S3BackupModeEnabled,
}, false),

value := v.(string)
if value != "Disabled" && value != "Enabled" {
errors = append(errors, fmt.Errorf(
"%q must be one of 'Disabled', 'Enabled'", k))
}
return
},
},

"s3_backup_configuration": s3ConfigurationSchema(),

"cloudwatch_logging_options": cloudWatchLoggingOptionsSchema(),

"processing_configuration": processingConfigurationSchema(),
Expand Down Expand Up @@ -852,6 +869,11 @@ func createExtendedS3Config(d *schema.ResourceData) *firehose.ExtendedS3Destinat
configuration.CloudWatchLoggingOptions = extractCloudWatchLoggingConfiguration(s3)
}

if s3BackupMode, ok := s3["s3_backup_mode"]; ok {
configuration.S3BackupMode = aws.String(s3BackupMode.(string))
configuration.S3BackupConfiguration = expandS3BackupConfig(d.Get("extended_s3_configuration").([]interface{})[0].(map[string]interface{}))
}

return configuration
}

Expand Down Expand Up @@ -927,6 +949,11 @@ func updateExtendedS3Config(d *schema.ResourceData) *firehose.ExtendedS3Destinat
configuration.CloudWatchLoggingOptions = extractCloudWatchLoggingConfiguration(s3)
}

if s3BackupMode, ok := s3["s3_backup_mode"]; ok {
configuration.S3BackupMode = aws.String(s3BackupMode.(string))
configuration.S3BackupUpdate = updateS3BackupConfig(d.Get("extended_s3_configuration").([]interface{})[0].(map[string]interface{}))
}

return configuration
}

Expand Down
17 changes: 15 additions & 2 deletions aws/resource_aws_kinesis_firehose_delivery_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func TestAccAWSKinesisFirehoseDeliveryStream_ExtendedS3Updates(t *testing.T) {
},
},
},
S3BackupMode: aws.String("Enabled"),
}

resource.Test(t, resource.TestCase{
Expand Down Expand Up @@ -489,12 +490,15 @@ func testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(stream *firehose.Del
// destination. For simplicity, our test only have a single S3 or
// Redshift destination, so at this time it's safe to match on the first
// one
var match, processingConfigMatch bool
var match, processingConfigMatch, matchS3BackupMode bool
for _, d := range stream.Destinations {
if d.ExtendedS3DestinationDescription != nil {
if *d.ExtendedS3DestinationDescription.BufferingHints.SizeInMBs == *es.BufferingHints.SizeInMBs {
match = true
}
if *d.ExtendedS3DestinationDescription.S3BackupMode == *es.S3BackupMode {
matchS3BackupMode = true
}

processingConfigMatch = len(es.ProcessingConfiguration.Processors) == len(d.ExtendedS3DestinationDescription.ProcessingConfiguration.Processors)
}
Expand All @@ -505,6 +509,9 @@ func testAccCheckAWSKinesisFirehoseDeliveryStreamAttributes(stream *firehose.Del
if !processingConfigMatch {
return fmt.Errorf("Mismatch extended s3 ProcessingConfiguration.Processors count, expected: %s, got: %s", es, stream.Destinations)
}
if !matchS3BackupMode {
return fmt.Errorf("Mismatch extended s3 S3BackupMode, expected: %s, got: %s", es, stream.Destinations)
}
}

if redshiftConfig != nil {
Expand Down Expand Up @@ -956,7 +963,8 @@ resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
parameter_value = "${aws_lambda_function.lambda_function_test.arn}:$LATEST"
}]
}]
}]
}],
s3_backup_mode = "Disabled"
}
}
`
Expand Down Expand Up @@ -1053,6 +1061,11 @@ resource "aws_kinesis_firehose_delivery_stream" "test_stream" {
buffer_size = 10
buffer_interval = 400
compression_format = "GZIP"
s3_backup_mode = "Enabled"
s3_backup_configuration {
role_arn = "${aws_iam_role.firehose.arn}"
bucket_arn = "${aws_s3_bucket.bucket.arn}"
}
}
}
`
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/kinesis_firehose_delivery_stream.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ be used.
The `extended_s3_configuration` object supports the same fields from `s3_configuration` as well as the following:

* `processing_configuration` - (Optional) The data processing configuration. More details are given below.
* `s3_backup_mode` - (Optional) The Amazon S3 backup mode. Valid values are `Disabled` and `Enabled`. Default value is `Disabled`.
* `s3_backup_configuration` - (Optional) The configuration for backup in Amazon S3. Required if `s3_backup_mode` is `Enabled`. Supports the same fields as `s3_configuration` object.

The `redshift_configuration` object supports the following:

Expand Down