Module Outputs
Discuss and review the Terraform module outputs.
We'll cover the following...
We’re familiar with the modules’ outputs, but in this lesson, we’ll look at the more nuanced use of outputs and their visibility to other modules.
Terraform outputs and module relationships become more important as our scripts become increasingly sophisticated.
A simple output module
While module inputs are defined with the variable
keyword, outputs are defined with the output
keyword. We’re going to type in another local module that outputs the filename
of a local_file
resource like this:
variable filename { default = "default_filename.txt" } variable content { default = "Hello terraform local output module!" } output filename { value = var.filename } resource "local_file" "hello_local_output" { content = var.content filename = var.filename }
The ltthw_output module structure
Now we type in the consumer module, output_module_consumer
, that sources the output_module
.
What do we expect to happen when we apply this module:
variable filename { default = "default_filename.txt" } variable content { default = "Hello terraform local output module!" } output filename { value = var.filename } resource "local_file" "hello_local_output" { content = var.content filename = var.filename }
output_module_consumer sources the "output_module
We can see that nothing was mentioned in any output and no filename ...