Terragrunt dependencies/outputs problem

Hi everyone!

I having a problem working with Terragrunt and module dependencies. I have a Kinesis Stream, a Lambda function consuming and processing events from Kinesis, and a SQS queue as a dead-letter queue if something went wrong when the Lambda function process an event.

Terraform module file

Using the following Terraform module, I create an event-mapping between the Kinesis Stream and the Lambda function.

resource "aws_lambda_event_source_mapping" "kinesis_lambda_event_mapping" {

    // more variables here

    function_name      = aws_lambda_function.my_lambda_function.arn
    event_source_arn   = var.kinesis_stream_arn

    destination_config {
      on_failure {
        destination_arn = var.sqs_dlq_arn
      }
    }
}

Terragrunt file

In my Terragrunt file, I specified Kinesis and SQS as dependencies, because I need the ARN of the Kinesis Stream and the SQS queue before to create the Event Source Mapping.

# These are the dependencies with other modules

dependencies {
  paths = ["..//kinesis", "..//sqs"]
}

dependency "kinesis" {
  config_path = "..//kinesis"

  mock_outputs = {
    stream_arn  = "fake-stream-arn"
    stream_name = "fake-stream-name"
  }

  skip_outputs = true
}

dependency "sqs" {
  config_path = "..//sqs"
}

Problem

When I execute a terragrunt run-all plan I get the following error:

ERRO[0016] Module lambda has finished with an error: sqs/terragrunt.hcl is a dependency of lambda/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block.

So, I tried adding mock_outputs in the SQS dependency, because the SQS in not applied yet:

dependency "sqs" {
  config_path = "..//sqs"

  mock_outputs = {
    sqs_dead_letter_queue_arn = "fake-sqs-arn"
  }

  skip_outputs = true
}

When I execute a terragrunt run-all plan again, I get this:

Error: "destination_config.0.on_failure.0.destination_arn" (fake-sqs-arn) is an invalid ARN: arn: invalid prefix

  on main.tf line 33, in resource "aws_lambda_event_source_mapping" "kinesis_lambda_event_mapping":
  33:         destination_arn = var.sqs_dlq_arn

Also, I tried removing the skip_outputs flag and keeping the mock_outputs, but I get an error like “not outputs defined”

Hi @nazrak ,

The main issue here is that your module depends on a valid ARN for the SQS queue to be passed in, and your mock value for the ARN that comes from the dependency is not in the valid format.

I believe terraform only does a basic static check of the arn format, so my guess is that you will be able to work around this issue if you set fake-sqs-arn to some fake arn in the correct format (e.g., arn:aws:sqs:us-east-2:123456789012:myqueue-15PG5C2FC1CW8).

Hope this helps!

Yori