Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11377

Reference to undeclared resource - when resource exists

$
0
0

Hello

I have 3 terraform files. main,tf, sqs.tf and mapping.tf

main.tf - Creates lambda function
sqs.tf - Creates SQS queue
mapping.tf - creates - Lambda event source mapping

main.tf

resource "aws_lambda_function" "reminder_function" {
  ephemeral_storage {
    size = 512
  }

  function_name                  = "reminder-function"
  handler                        = "reminder.handler"
  filename                       = "./src/node.zip" 
  memory_size                    = 512
  package_type                   = "Zip"
  reserved_concurrent_executions = -1
  role                           = aws_iam_role.reminder.arn
  runtime                        = "nodejs16.x"
  source_code_hash               = "sdsdlsll2smekjdkdfjjd/02aYdnbRedk="
  timeout                        = 30
  tracing_config {
    mode = "PassThrough"
  }
}

sqs.tf

resource "aws_sqs_queue" "reminder_queue" {
  kms_data_key_reuse_period_seconds = 300
  max_message_size                  = 204800
  message_retention_seconds         = 360000
  name                              = "reminder-queue"
  sqs_managed_sse_enabled           = true
  visibility_timeout_seconds        = 30
}

mapping.tf

resource "aws_lambda_event_source_mapping" "reminder_function_mapping" {
  event_source_arn = aws_sqs_queue.reminder_queue.arn
  function_name    = aws_lambda_function.reminder_function.arn
}

When applying the project, I am getting the following message

Error: Reference to undeclared resource
on mapping.tf line 3, in resource “aws_lambda_event_source_mapping” “reminder_function_mapping”:

function_name = aws_lambda_function.reminder_function.arn

A managed resource “aws_lambda_function” “reminder_function” has not been declared in the root module.

Can anyone help me to understand what is wrong here?
Apparently I have function created, but for some reason aws_lambda_event_source_mapping ignores that.

P.S. -1
I am using Terraform Cloud, with VCS driven workspace

P.S. -2
I’ve tried to add depends_on... lambda function, with no luck

Thanks in advance

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 11377

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>