Accessing output from module in Terraform 12

HI all!

I have a module that creates a lambda function and some related stuff. I want this module to output the ARN of the lambda it creates, however I can’t seem to get it to output anything.

At present I have configured the following output in the module for testing purposes (the variable testing is defined elsewhere):

# cat outputs.tf 
output "testing" {
  value = var.testing
}

I’m calling the module as follows:

module "function_deploy" {
  source = "git::https://module/"

  function_name = "name"
  function_handler = "lambda.lambda_handler"
  function_runtime = "python3.6"
  vpc_function = "false"
}

It applies fine, the function is built using the newest version of the module, there are no errors and everything is dandy, except no output is produced. Statefile shows:

  "outputs": {},

What am I missing here?

Thanks!

Hi @suaswe,

An output from a child module is exposed for use by its calling module, not at the root. In order to see this in the terraform apply output and in the outputs part of the state snapshot you’ll need to export it from the root module too:

output "testing" {
  value = module.function_deploy.testing
}

Each module instance has its own separate set of output values, and only the ones from the root module (the one containing your module "function_deploy" block) are exposed as outputs for the configuration as a whole.

1 Like

Thank you, I figured it out shortly after posting. :slight_smile: I was hoping I could keep the output in a “centralised” location (i.e. the module I’m calling) but I see now that I cannot.

I’m still trying to figure this one out a bit. I have created a module and in there, I have specified an output. I then go to use that module with a count number of 3 and want to reference the output from that module in another resource. As i’m using count, it adds a layer of complexity that I can’t seem to solve. Any ideas @apparentlymart