Hi everyone, I am new to terraform. I have a ques...
# terraform
d
Hi everyone, I am new to terraform. I have a question about how to get an ARN from a resource that is created by a module. For example the AWS Lambda module. If I create a lambda using that module how do I reference the ARN for the lambda? This is how I reference the module in my codebase:
Copy code
module "build_teams_notify" {
  source = "terraform-aws-modules/lambda/aws"
build_teams_notify. aws_lambda_function.arn
is not working.
t
@Dallas Despain you need to reference it via an output from the module. In the module:
Copy code
output "aws_lambda_function_arn" {
  value = aws_lambda_function.arn
}
in the parent:
Copy code
locals {
  my_important_arn = module.build_teams_notify.aws_lambda_function_arn
  # my_important_arn = module.build_teams_notify.<name of the output you created in the module>
}
d
Thank you @Troy Knapp!
@Troy Knapp ugh... I feel like this is a very ignorant question, but when I put "in the module" I'm thinking it's inside the module block, but that must not be right because when I put this in the module block
Copy code
output "aws_lambda_function_arn" {
  value = aws_lambda_function.arn
}
Terraform says this:
Copy code
│ Error: Unsupported block type
│
│   on <http://notify.tf|notify.tf> line 3, in module "build_teams_notify":
│    3:   output "teams_notify_aws_lambda_function_arn" {
│
│ Blocks of type "output" are not expected here.
╵
When I try to put it after the module block it says
Copy code
╷
│ Error: Reference to undeclared resource
│
│   on <http://notify.tf|notify.tf> line 85, in output "teams_notify_aws_lambda_function_arn":
│   85:   value = aws_lambda_function.arn
│
│ A managed resource "aws_lambda_function" "arn" has not been declared in the root module.
╵
t
No, your module block is referring to a package of terraform code. In that package you need to add an output.
d
Thanks again!
I thought that module block was referring to a module on the terraform registry
t
This is probably what you want
d
So would referencing it look something like this (using the locals block you mentioned)
Copy code
locals {
  my_important_arn = terraform-aws-modules.lambda_function_arn
}
t
you're referencing a module, so you need that prefix, then you need the name of the module, then you need the output... which is how I wrote it
d
I got it!