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

resource/aws_lambda_event_source_mapping: Adding ParallelizationFactor, MaximumRecordAgeInSeconds, BisectBatchOnFunctionError, MaximumRetryAttempts, DestinationConfig #11100

Merged
merged 12 commits into from
Feb 21, 2020
95 changes: 94 additions & 1 deletion aws/resource_aws_lambda_event_source_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,52 @@ func resourceAwsLambdaEventSourceMapping() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"parallelization_factor": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(1, 10),
Computed: true,
},
"maximum_retry_attempts": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(0, 10000),
Computed: true,
},
"maximum_record_age_in_seconds": {
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(60, 604800),
Computed: true,
},
"bisect_batch_on_function_error": {
Type: schema.TypeBool,
Optional: true,
},
"destination_config": {
kostas-theo marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeList,
Optional: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"on_failure": {
kostas-theo marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"destination_arn": {
kostas-theo marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},
},
},
},
},
},
},
"function_arn": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -160,6 +206,25 @@ func resourceAwsLambdaEventSourceMappingCreate(d *schema.ResourceData, meta inte
t, _ := time.Parse(time.RFC3339, startingPositionTimestamp.(string))
params.StartingPositionTimestamp = aws.Time(t)
}
if parallelizationFactor, ok := d.GetOk("parallelization_factor"); ok {
params.ParallelizationFactor = aws.Int64(int64(parallelizationFactor.(int)))
}

if maximumRetryAttempts, ok := d.GetOk("maximum_retry_attempts"); ok {
params.MaximumRetryAttempts = aws.Int64(int64(maximumRetryAttempts.(int)))
}

if maximumRecordAgeInSeconds, ok := d.GetOk("maximum_record_age_in_seconds"); ok {
params.MaximumRecordAgeInSeconds = aws.Int64(int64(maximumRecordAgeInSeconds.(int)))
}

if bisectBatchOnFunctionError, ok := d.GetOk("bisect_batch_on_function_error"); ok {
params.BisectBatchOnFunctionError = aws.Bool(bisectBatchOnFunctionError.(bool))
}

if vDest, ok := d.GetOk("destination_config"); ok {
params.SetDestinationConfig(expandLambdaEventSourceMappingDestinationConfig(vDest.([]interface{})))
}

// IAM profiles and roles can take some time to propagate in AWS:
// http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#launch-instance-with-role-console
Expand Down Expand Up @@ -227,6 +292,13 @@ func resourceAwsLambdaEventSourceMappingRead(d *schema.ResourceData, meta interf
d.Set("state_transition_reason", eventSourceMappingConfiguration.StateTransitionReason)
d.Set("uuid", eventSourceMappingConfiguration.UUID)
d.Set("function_name", eventSourceMappingConfiguration.FunctionArn)
d.Set("parallelization_factor", eventSourceMappingConfiguration.ParallelizationFactor)
d.Set("maximum_retry_attempts", eventSourceMappingConfiguration.MaximumRetryAttempts)
d.Set("maximum_record_age_in_seconds", eventSourceMappingConfiguration.MaximumRecordAgeInSeconds)
d.Set("bisect_batch_on_function_error", eventSourceMappingConfiguration.BisectBatchOnFunctionError)
if err := d.Set("destination_config", flattenLambdaEventSourceMappingDestinationConfig(eventSourceMappingConfiguration.DestinationConfig)); err != nil {
return fmt.Errorf("error setting destination_config: %s", err)
}

state := aws.StringValue(eventSourceMappingConfiguration.State)

Expand Down Expand Up @@ -289,9 +361,30 @@ func resourceAwsLambdaEventSourceMappingUpdate(d *schema.ResourceData, meta inte

// AWS API will fail if this parameter is set (even as default value) for sqs event source. Ideally this should be implemented in GO SDK or AWS API itself.
eventSourceArn, err := arn.Parse(d.Get("event_source_arn").(string))
if err != nil {
return fmt.Errorf("Error updating event source mapping: %s", err)
}

if err == nil && eventSourceArn.Service != "sqs" {
if eventSourceArn.Service != "sqs" {
params.MaximumBatchingWindowInSeconds = aws.Int64(int64(d.Get("maximum_batching_window_in_seconds").(int)))

if parallelizationFactor, ok := d.GetOk("parallelization_factor"); ok {
params.SetParallelizationFactor(int64(parallelizationFactor.(int)))
}

if maximumRetryAttempts, ok := d.GetOk("maximum_retry_attempts"); ok {
kostas-theo marked this conversation as resolved.
Show resolved Hide resolved
params.SetMaximumRetryAttempts(int64(maximumRetryAttempts.(int)))
}

params.MaximumRecordAgeInSeconds = aws.Int64(int64(d.Get("maximum_record_age_in_seconds").(int)))

if bisectBatchOnFunctionError, ok := d.GetOk("bisect_batch_on_function_error"); ok {
params.SetBisectBatchOnFunctionError(bisectBatchOnFunctionError.(bool))
}

if vDest, ok := d.GetOk("destination_config"); ok {
params.SetDestinationConfig(expandLambdaEventSourceMappingDestinationConfig(vDest.([]interface{})))
}
}

err = resource.Retry(5*time.Minute, func() *resource.RetryError {
Expand Down
Loading