2
votes

I am trying to define a terraform output block that returns the ARN of a Lambda function. The Lambda is defined in a sub-module. According to the documentation it seems like the lambda should just have an ARN attribute already: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lambda_function#arn

Using that as a source I thought I should be able to do the following:

output "lambda_arn" {
  value = module.aws_lambda_function.arn
}

This generates the following error:

Error: Unsupported attribute

  on main.tf line 19, in output "lambda_arn":
  19:   value = module.aws_lambda_function.arn

This object does not have an attribute named "arn".

I would appreciate any input, thanks.

1

1 Answers

3
votes

Documentation is correct. Data source data.aws_lambda_function has arn attribute. However, you are trying to access the arn from a custom module module.aws_lambda_function. To do this you have to define output arn in your module.

So in your module you should have something like this:

data "aws_lambda_function" "existing" {
  function_name = "function-to-get"
}

output "arn" {
  value = data.aws_lambda_function.existing.arn
}

Then if you have your module called aws_lambda_function:

module "aws_lambda_function" {
   source = "path-to-module"   
}

you will be able to access the arn:

module.aws_lambda_function.arn