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

Request for an example of Lambda pulling from SQS and provisioning all the involved resources. #63

Closed
ezeql opened this issue Jul 17, 2020 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@ezeql
Copy link

ezeql commented Jul 17, 2020

Hello,

Thanks for this useful component.

I would like to request an example of https://github.com/spring-media/terraform-aws-lambda/tree/master/examples/example-with-sqs-event involving the creation of the required SQS queue instead of hard-coding the ARN on it.

@moritzzimmer moritzzimmer added the question Further information is requested label Jul 18, 2020
@moritzzimmer moritzzimmer self-assigned this Jul 18, 2020
@moritzzimmer
Copy link
Contributor

Hi @ezeql,

you can include the SQS resource directly in your module like this:

resource "aws_sqs_queue" "example" {
  name = "example"
}

module "issue-63" {
  source  = "spring-media/lambda/aws"
  version = "5.2.0"

  filename      = "${path.module}/../bin/issue-63.zip"
  function_name = "tf-issue-63"
  handler       = "issue-63"
  runtime       = "go1.x"

  event = {
    type             = "sqs"
    event_source_arn = aws_sqs_queue.example.arn
  }
}

This module relies heavily on count to determine which resources should be created. So if you just run

$ terraform apply -var region=us-west-2

which works when using a hard-coded ARN or a data source, you'll get those errors:

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.

Like described in the error message, just add an intermediate terraform command:

$ terraform apply -var region=us-west-2 -target aws_sqs_queue.example 
$ terraform apply -var region=us-west-2

Let me know if this answers your question.

@ezeql
Copy link
Author

ezeql commented Jul 22, 2020

Thank you @moritzzimmer

@ezeql ezeql closed this as completed Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants