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

feat: add support for retry policies and dead letter config for aws_cloudwatch_event_target resources #17241

Merged
merged 11 commits into from
Feb 18, 2021
73 changes: 73 additions & 0 deletions aws/resource_aws_cloudwatch_event_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,38 @@ func resourceAwsCloudWatchEventTarget() *schema.Resource {
},
},
},

"retry_policy": {
sthulb marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"maximum_event_age_in_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntAtLeast(60),
},
"maximum_retry_attempts": {
Type: schema.TypeInt,
Optional: true,
},
},
},
},

"dead_letter_config": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateArn,
},
},
},
},
},
}
}
Expand Down Expand Up @@ -434,6 +466,14 @@ func buildPutTargetInputStruct(d *schema.ResourceData) *events.PutTargetsInput {
e.InputTransformer = expandAwsCloudWatchEventTransformerParameters(v.([]interface{}))
}

if v, ok := d.GetOk("retry_policy"); ok {
e.RetryPolicy = expandAwsCloudWatchEventRetryPolicyParameters(v.([]interface{}))
}

if v, ok := d.GetOk("dead_letter_config"); ok {
e.DeadLetterConfig = expandAwsCloudWatchEventDeadLetterConfigParameters(v.([]interface{}))
}

input := events.PutTargetsInput{
Rule: aws.String(d.Get("rule").(string)),
Targets: []*events.Target{e},
Expand Down Expand Up @@ -485,6 +525,39 @@ func expandAwsCloudWatchEventTargetEcsParameters(config []interface{}) *events.E

return ecsParameters
}

func expandAwsCloudWatchEventRetryPolicyParameters(rp []interface{}) *events.RetryPolicy {
retryPolicy := &events.RetryPolicy{}

for _, v := range rp {
params := v.(map[string]interface{})

if val, ok := params["maximum_event_age_in_seconds"].(int); ok {
retryPolicy.MaximumEventAgeInSeconds = aws.Int64(int64(val))
}

if val, ok := params["maximum_retry_attempts"].(int); ok {
retryPolicy.MaximumRetryAttempts = aws.Int64(int64(val))
}
}

return retryPolicy
}

func expandAwsCloudWatchEventDeadLetterConfigParameters(dlp []interface{}) *events.DeadLetterConfig {
deadLetterConfig := &events.DeadLetterConfig{}

for _, v := range dlp {
params := v.(map[string]interface{})

if val, ok := params["arn"].(string); ok && val != "" {
deadLetterConfig.Arn = aws.String(val)
}
}

return deadLetterConfig
}

func expandAwsCloudWatchEventTargetEcsParametersNetworkConfiguration(nc []interface{}) *events.NetworkConfiguration {
if len(nc) == 0 {
return nil
Expand Down