Wednesday, February 21, 2024
HomeSoftware EngineeringThe right way to view a Terraform Module’s Output

The right way to view a Terraform Module’s Output


An output in Terraform is a method 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 may 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 may output the values to the console as soon as the terraform apply step has efficiently run.

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

Outputs are solely rendered to the fast caller, and never traversed up the decision tree to the initiation primary.tf.

An instance venture construction

./
  ./modules/
      ./example_mod
          outputs.tf
          sources.tf
./primary.tf

In our primary.tf we name:

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

This won’t 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:

The right way to cross a Module’s Output up the tree to the Guardian

./
  ./modules/
      ./example_mod
          outputs.tf
          sources.tf
./primary.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
}
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments