Skip to content

scaling_config block causes invalid configuration when defaulted and wrapped in list #693

@Eliaslis

Description

@Eliaslis

Description

When creating a Lambda function with an SQS trigger like the following:

triggers = {
  "trigger" = {
    trigger_type            = "sqs"
    source_arn              = data.aws_sqs_queue.notifier.arn
    function_response_types = ["ReportBatchItemFailures"]
  }
}

If scaling_config is not explicitly defined, it defaults to [].
However, in the module’s main.tf file, the following block is used:

dynamic "scaling_config" {
  for_each = try([each.value.scaling_config], [])
  content {
    maximum_concurrency = try(scaling_config.value.maximum_concurrency, null)
  }
}

This try([each.value.scaling_config], []) causes the value to be wrapped in a list, and when scaling_config is not defined, the for_each receives [{}], which leads to an invalid configuration and triggers an error (see screenshot below).

After modifying the block to not wrap the value in a list, like so:

dynamic "scaling_config" {
  for_each = try(each.value.scaling_config, [])
  content {
    maximum_concurrency = try(scaling_config.value.maximum_concurrency, null)
  }
}

The issue was resolved successfully and the plan returned:

No changes. Your infrastructure matches the configuration.

✋ I have searched the open/closed issues and my issue is not listed.

⚠️ Note

Before submitting this issue:

  • Removed the .terraform/ directory

  • Re-initialized using terraform init

  • Re-tested with terraform apply

Versions

  • Module version: 8.0.1

  • Terraform version: v1.12.2

  • Provider version(s): provider registry.terraform.io/hashicorp/aws v6.4.0

Reproduction Code [Required]

Steps to reproduce:

  1. Create a Lambda with a trigger as shown above

  2. Do not define scaling_config

  3. Use the original block:

for_each = try([each.value.scaling_config], [])
  1. Run terraform apply

Expected behavior

Terraform should detect no changes when scaling_config is undefined and safely skip it.

Actual behavior

Terraform tries to create an empty scaling_config {} block which is invalid for this resource.

Terminal Output Screenshot(s)

Image

Additional context

A small change in how for_each is constructed in the dynamic block resolves the issue and avoids unintended creation of an invalid scaling_config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions