Skip to content

Commit

Permalink
Changes from hashicorp#38245.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Jul 18, 2024
1 parent c39b05c commit c437a84
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 103 deletions.
3 changes: 3 additions & 0 deletions .changelog/38245.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_kinesis_firehose_delivery_stream: Add `secrets_manager_configuration` to `http_endpoint_configuration`
```
208 changes: 107 additions & 101 deletions internal/service/firehose/delivery_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,33 +192,6 @@ func resourceDeliveryStream() *schema.Resource {
},
}
}
secretsManagerConfigurationSchema := func() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrEnabled: {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"secret_arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidARN,
},
names.AttrRoleARN: {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidARN,
},
},
},
}
}
requestConfigurationSchema := func() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Expand Down Expand Up @@ -317,6 +290,34 @@ func resourceDeliveryStream() *schema.Resource {
Elem: s3ConfigurationElem(),
}
}
secretsManagerConfigurationSchema := func() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
names.AttrEnabled: {
Type: schema.TypeBool,
Optional: true,
Computed: true,
ForceNew: true,
},
"secret_arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidARN,
},
names.AttrRoleARN: {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidARN,
},
},
},
}
}

return map[string]*schema.Schema{
names.AttrARN: {
Expand Down Expand Up @@ -807,7 +808,8 @@ func resourceDeliveryStream() *schema.Resource {
Default: types.HttpEndpointS3BackupModeFailedDataOnly,
ValidateDiagFunc: enum.Validate[types.HttpEndpointS3BackupMode](),
},
"s3_configuration": s3ConfigurationSchema(),
"s3_configuration": s3ConfigurationSchema(),
"secrets_manager_configuration": secretsManagerConfigurationSchema(),
names.AttrURL: {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -2338,12 +2340,9 @@ func expandProcessorParameter(processorParameter map[string]interface{}) types.P

func expandSecretsManagerConfiguration(tfMap map[string]interface{}) *types.SecretsManagerConfiguration {
config := tfMap["secrets_manager_configuration"].([]interface{})

if len(config) == 0 || config[0] == nil {
// It is possible to just pass nil here, but this seems to be the
// canonical form that AWS uses, and is less likely to produce diffs.
return &types.SecretsManagerConfiguration{
Enabled: aws.Bool(false),
}
return nil
}

secretsManagerConfiguration := config[0].(map[string]interface{})
Expand Down Expand Up @@ -2891,81 +2890,86 @@ func expandSplunkDestinationUpdate(splunk map[string]interface{}) *types.SplunkD
return configuration
}

func expandHTTPEndpointDestinationConfiguration(httpEndpoint map[string]interface{}) *types.HttpEndpointDestinationConfiguration {
roleARN := httpEndpoint[names.AttrRoleARN].(string)
configuration := &types.HttpEndpointDestinationConfiguration{
RetryOptions: expandHTTPEndpointRetryOptions(httpEndpoint),
RoleARN: aws.String(roleARN),
S3Configuration: expandS3DestinationConfiguration(httpEndpoint["s3_configuration"].([]interface{})),
func expandHTTPEndpointDestinationConfiguration(tfMap map[string]interface{}) *types.HttpEndpointDestinationConfiguration {
roleARN := tfMap[names.AttrRoleARN].(string)
apiObject := &types.HttpEndpointDestinationConfiguration{
EndpointConfiguration: expandHTTPEndpointConfiguration(tfMap),
RetryOptions: expandHTTPEndpointRetryOptions(tfMap),
RoleARN: aws.String(roleARN),
S3Configuration: expandS3DestinationConfiguration(tfMap["s3_configuration"].([]interface{})),
}

configuration.EndpointConfiguration = expandHTTPEndpointConfiguration(httpEndpoint)

bufferingHints := &types.HttpEndpointBufferingHints{}

if bufferingInterval, ok := httpEndpoint["buffering_interval"].(int); ok {
bufferingHints.IntervalInSeconds = aws.Int32(int32(bufferingInterval))
if v, ok := tfMap["buffering_interval"].(int); ok {
bufferingHints.IntervalInSeconds = aws.Int32(int32(v))
}
if bufferingSize, ok := httpEndpoint["buffering_size"].(int); ok {
bufferingHints.SizeInMBs = aws.Int32(int32(bufferingSize))
if v, ok := tfMap["buffering_size"].(int); ok {
bufferingHints.SizeInMBs = aws.Int32(int32(v))
}
configuration.BufferingHints = bufferingHints
apiObject.BufferingHints = bufferingHints

if _, ok := httpEndpoint["processing_configuration"]; ok {
configuration.ProcessingConfiguration = expandProcessingConfiguration(httpEndpoint, destinationTypeHTTPEndpoint, roleARN)
if _, ok := tfMap["cloudwatch_logging_options"]; ok {
apiObject.CloudWatchLoggingOptions = expandCloudWatchLoggingOptions(tfMap)
}

if _, ok := httpEndpoint["request_configuration"]; ok {
configuration.RequestConfiguration = expandHTTPEndpointRequestConfiguration(httpEndpoint)
if _, ok := tfMap["processing_configuration"]; ok {
apiObject.ProcessingConfiguration = expandProcessingConfiguration(tfMap, destinationTypeHTTPEndpoint, roleARN)
}

if _, ok := httpEndpoint["cloudwatch_logging_options"]; ok {
configuration.CloudWatchLoggingOptions = expandCloudWatchLoggingOptions(httpEndpoint)
if _, ok := tfMap["request_configuration"]; ok {
apiObject.RequestConfiguration = expandHTTPEndpointRequestConfiguration(tfMap)
}
if s3BackupMode, ok := httpEndpoint["s3_backup_mode"]; ok {
configuration.S3BackupMode = types.HttpEndpointS3BackupMode(s3BackupMode.(string))

if v, ok := tfMap["s3_backup_mode"]; ok {
apiObject.S3BackupMode = types.HttpEndpointS3BackupMode(v.(string))
}

return configuration
if _, ok := tfMap["secrets_manager_configuration"]; ok {
apiObject.SecretsManagerConfiguration = expandSecretsManagerConfiguration(tfMap)
}

return apiObject
}

func expandHTTPEndpointDestinationUpdate(httpEndpoint map[string]interface{}) *types.HttpEndpointDestinationUpdate {
roleARN := httpEndpoint[names.AttrRoleARN].(string)
configuration := &types.HttpEndpointDestinationUpdate{
RetryOptions: expandHTTPEndpointRetryOptions(httpEndpoint),
RoleARN: aws.String(roleARN),
S3Update: expandS3DestinationUpdate(httpEndpoint["s3_configuration"].([]interface{})),
func expandHTTPEndpointDestinationUpdate(tfMap map[string]interface{}) *types.HttpEndpointDestinationUpdate {
roleARN := tfMap[names.AttrRoleARN].(string)
apiObject := &types.HttpEndpointDestinationUpdate{
EndpointConfiguration: expandHTTPEndpointConfiguration(tfMap),
RetryOptions: expandHTTPEndpointRetryOptions(tfMap),
RoleARN: aws.String(roleARN),
S3Update: expandS3DestinationUpdate(tfMap["s3_configuration"].([]interface{})),
}

configuration.EndpointConfiguration = expandHTTPEndpointConfiguration(httpEndpoint)

bufferingHints := &types.HttpEndpointBufferingHints{}

if bufferingInterval, ok := httpEndpoint["buffering_interval"].(int); ok {
bufferingHints.IntervalInSeconds = aws.Int32(int32(bufferingInterval))
if v, ok := tfMap["buffering_interval"].(int); ok {
bufferingHints.IntervalInSeconds = aws.Int32(int32(v))
}
if bufferingSize, ok := httpEndpoint["buffering_size"].(int); ok {
bufferingHints.SizeInMBs = aws.Int32(int32(bufferingSize))
if v, ok := tfMap["buffering_size"].(int); ok {
bufferingHints.SizeInMBs = aws.Int32(int32(v))
}
configuration.BufferingHints = bufferingHints
apiObject.BufferingHints = bufferingHints

if _, ok := httpEndpoint["processing_configuration"]; ok {
configuration.ProcessingConfiguration = expandProcessingConfiguration(httpEndpoint, destinationTypeHTTPEndpoint, roleARN)
if _, ok := tfMap["cloudwatch_logging_options"]; ok {
apiObject.CloudWatchLoggingOptions = expandCloudWatchLoggingOptions(tfMap)
}

if _, ok := httpEndpoint["request_configuration"]; ok {
configuration.RequestConfiguration = expandHTTPEndpointRequestConfiguration(httpEndpoint)
if _, ok := tfMap["processing_configuration"]; ok {
apiObject.ProcessingConfiguration = expandProcessingConfiguration(tfMap, destinationTypeHTTPEndpoint, roleARN)
}

if _, ok := httpEndpoint["cloudwatch_logging_options"]; ok {
configuration.CloudWatchLoggingOptions = expandCloudWatchLoggingOptions(httpEndpoint)
if _, ok := tfMap["request_configuration"]; ok {
apiObject.RequestConfiguration = expandHTTPEndpointRequestConfiguration(tfMap)
}

if s3BackupMode, ok := httpEndpoint["s3_backup_mode"]; ok {
configuration.S3BackupMode = types.HttpEndpointS3BackupMode(s3BackupMode.(string))
if v, ok := tfMap["s3_backup_mode"]; ok {
apiObject.S3BackupMode = types.HttpEndpointS3BackupMode(v.(string))
}

return configuration
if _, ok := tfMap["secrets_manager_configuration"]; ok {
apiObject.SecretsManagerConfiguration = expandSecretsManagerConfiguration(tfMap)
}

return apiObject
}

func expandHTTPEndpointCommonAttributes(ca []interface{}) []types.HttpEndpointCommonAttribute {
Expand Down Expand Up @@ -3484,9 +3488,9 @@ func flattenRedshiftDestinationDescription(description *types.RedshiftDestinatio
return []map[string]interface{}{m}
}

func flattenSnowflakeDestinationDescription(apiObject *types.SnowflakeDestinationDescription, configuredKeyPassphrase, configuredPrivateKey string) []map[string]interface{} {
func flattenSnowflakeDestinationDescription(apiObject *types.SnowflakeDestinationDescription, configuredKeyPassphrase, configuredPrivateKey string) []interface{} {
if apiObject == nil {
return []map[string]interface{}{}
return []interface{}{}
}

roleARN := aws.ToString(apiObject.RoleARN)
Expand Down Expand Up @@ -3515,7 +3519,7 @@ func flattenSnowflakeDestinationDescription(apiObject *types.SnowflakeDestinatio
tfMap["retry_duration"] = int(aws.ToInt32(apiObject.RetryOptions.DurationInSeconds))
}

return []map[string]interface{}{tfMap}
return []interface{}{tfMap}
}

func flattenSplunkDestinationDescription(description *types.SplunkDestinationDescription) []map[string]interface{} {
Expand Down Expand Up @@ -3906,32 +3910,34 @@ func flattenKinesisStreamSourceDescription(desc *types.KinesisStreamSourceDescri
return []interface{}{mDesc}
}

func flattenHTTPEndpointDestinationDescription(description *types.HttpEndpointDestinationDescription, configuredAccessKey string) []map[string]interface{} {
if description == nil {
return []map[string]interface{}{}
func flattenHTTPEndpointDestinationDescription(apiObject *types.HttpEndpointDestinationDescription, configuredAccessKey string) []interface{} {
if apiObject == nil {
return []interface{}{}
}
m := map[string]interface{}{
names.AttrAccessKey: configuredAccessKey,
names.AttrURL: aws.ToString(description.EndpointConfiguration.Url),
names.AttrName: aws.ToString(description.EndpointConfiguration.Name),
names.AttrRoleARN: aws.ToString(description.RoleARN),
"s3_backup_mode": description.S3BackupMode,
"s3_configuration": flattenS3DestinationDescription(description.S3DestinationDescription),
"request_configuration": flattenHTTPEndpointRequestConfiguration(description.RequestConfiguration),
"cloudwatch_logging_options": flattenCloudWatchLoggingOptions(description.CloudWatchLoggingOptions),
"processing_configuration": flattenProcessingConfiguration(description.ProcessingConfiguration, destinationTypeHTTPEndpoint, aws.ToString(description.RoleARN)),

tfMap := map[string]interface{}{
names.AttrAccessKey: configuredAccessKey,
"cloudwatch_logging_options": flattenCloudWatchLoggingOptions(apiObject.CloudWatchLoggingOptions),
names.AttrName: aws.ToString(apiObject.EndpointConfiguration.Name),
"processing_configuration": flattenProcessingConfiguration(apiObject.ProcessingConfiguration, destinationTypeHTTPEndpoint, aws.ToString(apiObject.RoleARN)),
"request_configuration": flattenHTTPEndpointRequestConfiguration(apiObject.RequestConfiguration),
names.AttrRoleARN: aws.ToString(apiObject.RoleARN),
"s3_backup_mode": apiObject.S3BackupMode,
"s3_configuration": flattenS3DestinationDescription(apiObject.S3DestinationDescription),
"secrets_manager_configuration": flattenSecretsManagerConfiguration(apiObject.SecretsManagerConfiguration),
names.AttrURL: aws.ToString(apiObject.EndpointConfiguration.Url),
}

if description.RetryOptions != nil {
m["retry_duration"] = int(aws.ToInt32(description.RetryOptions.DurationInSeconds))
if apiObject.BufferingHints != nil {
tfMap["buffering_interval"] = int(aws.ToInt32(apiObject.BufferingHints.IntervalInSeconds))
tfMap["buffering_size"] = int(aws.ToInt32(apiObject.BufferingHints.SizeInMBs))
}

if description.BufferingHints != nil {
m["buffering_interval"] = int(aws.ToInt32(description.BufferingHints.IntervalInSeconds))
m["buffering_size"] = int(aws.ToInt32(description.BufferingHints.SizeInMBs))
if apiObject.RetryOptions != nil {
tfMap["retry_duration"] = int(aws.ToInt32(apiObject.RetryOptions.DurationInSeconds))
}

return []map[string]interface{}{m}
return []interface{}{tfMap}
}

func expandDocumentIDOptions(tfMap map[string]interface{}) *types.DocumentIdOptions {
Expand Down
62 changes: 62 additions & 0 deletions internal/service/firehose/delivery_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,36 @@ func TestAccFirehoseDeliveryStream_HTTPEndpoint_retryDuration(t *testing.T) {
})
}

func TestAccFirehoseDeliveryStream_HTTPEndpoint_SecretsManagerConfiguration(t *testing.T) {
ctx := acctest.Context(t)
var stream types.DeliveryStreamDescription
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_kinesis_firehose_delivery_stream.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.FirehoseServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDeliveryStreamDestroy_ExtendedS3(ctx),
Steps: []resource.TestStep{
{
Config: testAccDeliveryStreamConfig_httpEndpointSecretsManager(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckDeliveryStreamExists(ctx, resourceName, &stream),
resource.TestCheckResourceAttr(resourceName, "http_endpoint_configuration.0.secret_manager_configuration.#", acctest.Ct1),
resource.TestCheckResourceAttr(resourceName, "http_endpoint_configuration.0.secret_manager_configuration.0.enabled", acctest.CtTrue),
resource.TestCheckResourceAttrPair(resourceName, "http_endpoint_configuration.0.secret_manager_configuration.0.secret_arn", "aws_secretsmanager_secret.test", names.AttrARN),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccFirehoseDeliveryStream_elasticSearchUpdates(t *testing.T) {
ctx := acctest.Context(t)
var stream types.DeliveryStreamDescription
Expand Down Expand Up @@ -4175,6 +4205,38 @@ resource "aws_kinesis_firehose_delivery_stream" "test" {
`, rName))
}

func testAccDeliveryStreamConfig_httpEndpointSecretsManager(rName string) string {
return acctest.ConfigCompose(testAccDeliveryStreamConfig_base(rName), fmt.Sprintf(`
resource "aws_secretsmanager_secret" "test" {
name = %[1]q
}
resource "aws_kinesis_firehose_delivery_stream" "test" {
depends_on = [aws_iam_role_policy.firehose]
name = %[1]q
destination = "http_endpoint"
http_endpoint_configuration {
url = "https://input-test.com:443"
name = "HTTP_test"
role_arn = aws_iam_role.firehose.arn
s3_configuration {
role_arn = aws_iam_role.firehose.arn
bucket_arn = aws_s3_bucket.bucket.arn
}
secret_manager_configuration {
enabled = true
role_arn = aws_iam_role.firehose.arn
secret_arn = aws_secretsmanager_secret.test.arn
}
}
}
`, rName))
}

func testAccDeliveryStreamConfig_baseElasticsearch(rName string) string {
return acctest.ConfigCompose(testAccDeliveryStreamConfig_base(rName), fmt.Sprintf(`
resource "aws_elasticsearch_domain" "test_cluster" {
Expand Down
Loading

0 comments on commit c437a84

Please sign in to comment.