Outputs

Terraform offer output values make information about your infrastructure available on the command line, and can expose information for other Terraform configurations to use.

About Output Values

  • A child module can use outputs to expose a subset of its resource attributes to a parent module.
  • A root module can use outputs to print certain values in the CLI output after running terraform apply.
  • When using remote state, root module outputs can be accessed by other configurations via a terraform_remote_state data source.

Resource instances managed by Terraform each export attributes whose values can be used elsewhere in configuration. Output values are a way to expose some of that information to the user of your module.

Declaring Output values

  • Here's an example:
1output "instance_ip_addr" {
2  value = aws_instance.server.private_ip
3}
  • This one gets the value of the priovate_ip address of an ec2 instance.
    • In a root module, this name is displayed to the user;
    • in a child module, it can be used to access the output's value.
  • In a parent module, outputs of child modules are available in expressions as;
    module...
  • For example, if a child module named web_server declared an output named instance_ip_addr, you could access that value as: module.web_server.instance_ip_addr