github.com/jmbataller/terraform@v0.6.8-0.20151125192640-b7a12e3a580c/website/source/intro/getting-started/outputs.html.md (about)

     1  ---
     2  layout: "intro"
     3  page_title: "Output Variables"
     4  sidebar_current: "gettingstarted-outputs"
     5  description: |-
     6    In the previous section, we introduced input variables as a way to parameterize Terraform configurations. In this page, we introduce output variables as a way to organize data to be easily queried and shown back to the Terraform user.
     7  ---
     8  
     9  # Output Variables
    10  
    11  In the previous section, we introduced input variables as a way
    12  to parameterize Terraform configurations. In this page, we
    13  introduce output variables as a way to organize data to be
    14  easily queried and shown back to the Terraform user.
    15  
    16  When building potentially complex infrastructure, Terraform
    17  stores hundreds or thousands of attribute values for all your
    18  resources. But as a user of Terraform, you may only be interested
    19  in a few values of importance, such as a load balancer IP,
    20  VPN address, etc.
    21  
    22  Outputs are a way to tell Terraform what data is important.
    23  This data is outputted when `apply` is called, and can be
    24  queried using the `terraform output` command.
    25  
    26  ## Defining Outputs
    27  
    28  Let's define an output to show us the public IP address of the
    29  elastic IP address that we create. Add this to any of your
    30  `*.tf` files:
    31  
    32  ```
    33  output "ip" {
    34  	value = "${aws_eip.ip.public_ip}"
    35  }
    36  ```
    37  
    38  This defines an output variables named "ip". The `value` field
    39  specifies what the value will be, and almost always contains
    40  one or more interpolations, since the output data is typically
    41  dynamic. In this case, we're outputting the
    42  `public_ip` attribute of the elastic IP address.
    43  
    44  Multiple `output` blocks can be defined to specify multiple
    45  output variables.
    46  
    47  ## Viewing Outputs
    48  
    49  Run `terraform apply` to populate the output. This only needs
    50  to be done once after the output is defined. The apply output
    51  should change slightly. At the end you should see this:
    52  
    53  ```
    54  $ terraform apply
    55  ...
    56  
    57  Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
    58  
    59  Outputs:
    60  
    61    ip = 50.17.232.209
    62  ```
    63  
    64  `apply` highlights the outputs. You can also query the outputs
    65  after apply-time using `terraform output`:
    66  
    67  ```
    68  $ terraform output ip
    69  50.17.232.209
    70  ```
    71  
    72  This command is useful for scripts to extract outputs.
    73  
    74  ## Next
    75  
    76  You now know how to parameterize configurations with input
    77  variables, extract important data using output variables,
    78  and bootstrap resources using provisioners.
    79  
    80  Next, we're going to take a look at
    81  [how to use modules](/intro/getting-started/modules.html), a useful
    82  abstraction to organization and reuse Terraform configurations.