Skip to content

How to view a Terraform Module’s Output

An output in Terraform is a way to view the result of an action that has been performed, or resource that has been created.

Let’s say that you have some code to create a Load Balancer, or Assign a Public IP. Once this action is complete, the output block will have access to this created value.

An simple output example

output "instance_ips" { value = aws_instance.web.*.public_ip } output "lb_address" { value = aws_alb.web.public_dns }
Code language: plaintext (plaintext)

This will output the values to the console once the terraform apply step has successfully run.

But what happens if you have some outputs in a module that your own Terraform calls?

Outputs are only rendered to the immediate caller, and not traversed up the call tree to the initiation

An example project structure

./ ./modules/ ./example_mod ./
Code language: plaintext (plaintext)

In our we call:

module "example_mod" { source = "./modules/example_mod" }
Code language: plaintext (plaintext)

This will not render any output to the console, as the is segmented to the module itself and not passed up the chain.

To get access to these outputs after module creation, we need to do the following:

How to pass a Module’s Output up the tree to the Parent

./ ./modules/ ./example_mod ./ ./ # <- add this
Code language: plaintext (plaintext)

In our file:

output "THE_INSTANCE_IPS" { value = module.example_mod.instance_ips } output "THE_LB_ADDRESS" { value = module.example_mod.lb_address }
Code language: plaintext (plaintext)

See also  [Solved] Instance Profile already exists in Terraform
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x