Request for an example of Lambda pulling from SQS and provisioning all the involved resources.
ezeql opened this issue · 2 comments
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.
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.
Thank you @moritzzimmer