Software Engineering

view a Terraform Module’s Output

view a Terraform Module’s Output
Written by admin


An output in Terraform is a solution to view the results of an motion that has been carried out, or useful resource that has been created.

Let’s say that you’ve some code to create a Load Balancer, or Assign a Public IP. As soon as this motion is full, the output block can have entry to this created worth.

An easy output instance

outputs.tf

output "instance_ips" {
  worth = aws_instance.internet.*.public_ip
}

output "lb_address" {
  worth = aws_alb.internet.public_dns
}

This can output the values to the console as soon as the terraform apply step has efficiently run.

However what occurs if in case you have some outputs in a module that your personal Terraform calls?

Outputs are solely rendered to the rapid caller, and never traversed up the decision tree to the initiation most important.tf.

An instance venture construction

./
  ./modules/
      ./example_mod
          outputs.tf
          assets.tf
./most important.tf

In our most important.tf we name:

module "example_mod" {
  supply  = "./modules/example_mod"
}

This is not going to render any output to the console, because the output.tf is segmented to the module itself and never handed up the chain.

To get entry to those outputs after module creation, we have to do the next:

move a Module’s Output up the tree to the Mum or dad

./
  ./modules/
      ./example_mod
          outputs.tf
          assets.tf
./most important.tf
./output.tf    # <- add this

In our output.tf file:

output "THE_INSTANCE_IPS" {
  worth = module.example_mod.instance_ips
}

output "THE_LB_ADDRESS" {
  worth = module.example_mod.lb_address
}

About the author

admin

Leave a Comment