Skip to content

aws_lambda_event_source_mapping: incorrectly setting values for optional resource parameters that weren't explicitly specified #14522

Closed
@dlenski

Description

@dlenski

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v0.12.29

* provider.aws: version = "~> 2.70"
* provider.null: version = "~> 2.1"
* provider.template: version = "~> 2.1"

Affected Resource(s)

  • aws_lambda_event_source_mapping

I attempted to modify this existing aws_lambda_event_source_mapping resource:

resource "aws_lambda_event_source_mapping" "event_source_mapping_name" {
  batch_size             = 1000
  event_source_arn       = var.dynamo_stream_arn
  enabled                = true
  function_name          = aws_lambda_function.lambda_n.arn
  starting_position      = "TRIM_HORIZON"
}

Originally-intended changes (The parallelization factor feature for AWS lambda stream processing was announced in November 2019 and added to Terraform in 2d5b2cd#diff-943f35dca31585fb17f97dbca05290db.)

 resource "aws_lambda_event_source_mapping" "event_source_mapping_name" {
   batch_size             = 1000
+  parallelization_factor = 10
   event_source_arn       = var.dynamo_stream_arn
   enabled                = true
   function_name          = aws_lambda_function.lambda_n.arn
   starting_position      = "TRIM_HORIZON"
 }

Execution of these changes fails:

Error updating Lambda event source mapping: InvalidParameter: 1 validation error(s) found.
- minimum field value of 60, UpdateEventSourceMappingInput.MaximumRecordAgeInSeconds.

terraform plan shows why:

   # aws_lambda_event_source_mapping.event_source_mapping_name will be updated in-place
   ~ resource "aws_lambda_event_source_mapping" "event_source_mapping_name" {
         batch_size                         = 1000
         bisect_batch_on_function_error     = false
         enabled                            = true
         event_source_arn                   = "arn:aws:dynamodb:..."
         function_arn                       = "arn:aws:lambda:..."
         function_name                      = "arn:aws:lambda:..."
         id                                 = "deadbeef-dead-beef-f00f-deadbeeff00f"
         last_modified                      = "2020-08-06T05:49:00Z"
         last_processing_result             = "OK"
         maximum_batching_window_in_seconds = 0        # BAD!
         maximum_record_age_in_seconds      = 0        # BAD!
         maximum_retry_attempts             = 0        # BAD!
       ~ parallelization_factor             = 0 -> 10
         starting_position                  = "TRIM_HORIZON"
         state                              = "Enabled"
         state_transition_reason            = "User action"
         uuid                               = "deadbeef-dead-beef-f00f-deadbeeff00f"
     }

There are three other new parameters, marked with # BAD! above, which are apparently being set to a value of 0 even though:

  • These parameters are all optional
  • 0 is not even a legal value for maximum_record_age_in_seconds or maximum_retry_attempts

https://github.com/terraform-providers/terraform-provider-aws/blob/1c28287a3de773d41e20c174591f0fd355c59e1b/aws/resource_aws_lambda_event_source_mapping.go#L99-L120

Terraform Configuration Files

See relevant excerpt above.

Debug Output

See relevant excerpt above.

Panic Output

N/A

Expected Behavior

  • Terraform should have not attempted to set the optional parameters of this resource, since no explicit value was indicated for them.

Actual Behavior

  • Terraform attempted to set the value of 3 not-explicitly-included optional, numeric parameters to a value of 0 (which is neither a default value, nor even a valid value, for some of them)

  • My hypothesis is that there is a faulty internal model for the state of an optional parameter that has never been set previously.

  • In order to work around this, I had to explicitly set these parameters to their default values:

 resource "aws_lambda_event_source_mapping" "event_source_mapping_name" {
   batch_size             = 1000
+  parallelization_factor = 10
   event_source_arn       = var.dynamo_stream_arn
   enabled                = true
   function_name          = aws_lambda_function.lambda_n.arn
   starting_position      = "TRIM_HORIZON"

+  # Workaround for apparent Terraform issue?
+  # Default values of these parameters seem to be: https://github.com/awsdocs/aws-cloudformation-user-guide/pull/767
+  maximum_batching_window_in_seconds = 0
+  maximum_record_age_in_seconds      = 604800
+  maximum_retry_attempts             = 10000
 }

Steps to Reproduce

  1. terraform apply

Important Factoids

N/A

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAddresses a defect in current functionality.service/lambdaIssues and PRs that pertain to the lambda service.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions