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

aws_lambda_event_source_mapping, attribute queues is misleading #31919

Closed
Tuzosdaniel12 opened this issue Jun 13, 2023 · 6 comments · Fixed by #31931
Closed

aws_lambda_event_source_mapping, attribute queues is misleading #31919

Tuzosdaniel12 opened this issue Jun 13, 2023 · 6 comments · Fixed by #31931
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/lambda Issues and PRs that pertain to the lambda service.
Milestone

Comments

@Tuzosdaniel12
Copy link

Description

Small observation after spending a day trying to understand validation failure when creating aws_lambda_event_source_mapping. After going back and carefully reading the docs I found that issue came from queues attribute.

At first glance one can assumed that queues = ["example"] will accept an array of strings with different queue

In result I created my resource in the following format.

resource "aws_lambda_event_source_mapping" "mq_triggers" {
  batch_size       = 10
  event_source_arn = var.broker_arn
  enabled          = true
  function_name    = aws_lambda_function.message_handler.arn
  queues           = ["START", "STOP", "STATUS"]

  source_access_configuration {
    type = "BASIC_AUTH"
    uri  = aws_secretsmanager_secret.broker_credentials.arn
  }
}

Which resulted in the following error.

Error: error creating Lambda Event Source Mapping (arn:aws:mq:....): ValidationException: 
	status code: 400

After banging my head I reread the docs and I soon understood that I could only send in a single string in the array.

queues - (Optional) The name of the Amazon MQ broker destination queue to consume. Only available for MQ sources. A single queue name must be specified

So I changed my code to do each queue in a loop.

resource "aws_lambda_event_source_mapping" "mq_triggers" {
  for_each = toset(local.queues)
  batch_size       = 10
  event_source_arn = var.broker_arn
  enabled          = true
  function_name    = aws_lambda_function.message_handler.arn
  queues           = [each.key]

  source_access_configuration {
    type = "BASIC_AUTH"
    uri  = aws_secretsmanager_secret_version.broker_credentials_secret.arn
  }
}

Is this the intended behavior? If yes, should the attribute name change to queues = "example"since is only accepts single value?

References

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_event_source_mapping

Would you like to implement a fix?

None

@Tuzosdaniel12 Tuzosdaniel12 added the needs-triage Waiting for first response or review from a maintainer. label Jun 13, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/lambda Issues and PRs that pertain to the lambda service. label Jun 13, 2023
@justinretzolk
Copy link
Member

justinretzolk commented Jun 13, 2023

Hey @Tuzosdaniel12 👋 Thank you for taking the time to raise this! The aws_lambda_event_source_mapping resource uses the lambda.CreateEventSourceMapping function from the AWS Go SDK. I've linked to lambda.CreateEventSourceMappingInput, which is the Go type used as an input to said function, since it's a bit more relevant in this case. The input for this function has a Queues field, which correlates to the queues argument for the resource in Terraform. To save you a click, the field has the following definition:

// (MQ) The name of the Amazon MQ broker destination queue to consume.
Queues []*string min:"1" type:"list"

In this case, the AWS Provider has followed the design principle of closely matching the underlying API, which is why the argument is a list type, despite my agreeing with you that it's a bit of an odd case (though not entirely unique in the context of the AWS API), and definitely see how it could cause confusion.

With that in mind, I would say that this is indeed expected behavior, and that the argument should be left as is.

@justinretzolk
Copy link
Member

As a follow up here, I noticed that neither the lambda.CreateEventSourceMapping, nor the argument's schema definition require that there is only a single element. While the documentation that you linked hints at it, it doesn't feel like strong enough wording when the API documentation for the function clearly indicates that the list has a fixed size of 1:

Array Members: Fixed number of 1 item.

I'd like to raise a pull request to make this more clear. Thank you again for taking the time to raise this and call it out!

@justinretzolk justinretzolk added enhancement Requests to existing resources that expand the functionality or scope. documentation Introduces or discusses updates to documentation. and removed needs-triage Waiting for first response or review from a maintainer. labels Jun 13, 2023
@github-actions github-actions bot added this to the v5.6.0 milestone Jun 23, 2023
@github-actions
Copy link

This functionality has been released in v5.6.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@Tuzosdaniel12
Copy link
Author

Thank you for the support!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. service/lambda Issues and PRs that pertain to the lambda service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants