github.com/lakshmikarc/terraform-2@v0.11.9-0.20181005183753-e0b7475984b7/website/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  ```hcl
    33  output "ip" {
    34    value = "${aws_eip.ip.public_ip}"
    35  }
    36  ```
    37  
    38  This defines an output variable named "ip". The name of the variable
    39  must conform to Terraform variable naming conventions if it is
    40  to be used as an input to other modules. The `value` field
    41  specifies what the value will be, and almost always contains
    42  one or more interpolations, since the output data is typically
    43  dynamic. In this case, we're outputting the
    44  `public_ip` attribute of the elastic IP address.
    45  
    46  Multiple `output` blocks can be defined to specify multiple
    47  output variables.
    48  
    49  ## Viewing Outputs
    50  
    51  Run `terraform apply` to populate the output. This only needs
    52  to be done once after the output is defined. The apply output
    53  should change slightly. At the end you should see this:
    54  
    55  ```
    56  $ terraform apply
    57  ...
    58  
    59  Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
    60  
    61  Outputs:
    62  
    63    ip = 50.17.232.209
    64  ```
    65  
    66  `apply` highlights the outputs. You can also query the outputs
    67  after apply-time using `terraform output`:
    68  
    69  ```
    70  $ terraform output ip
    71  50.17.232.209
    72  ```
    73  
    74  This command is useful for scripts to extract outputs.
    75  
    76  ## Next
    77  
    78  You now know how to parameterize configurations with input
    79  variables, extract important data using output variables,
    80  and bootstrap resources using provisioners.
    81  
    82  Next, we're going to take a look at
    83  [how to use modules](/intro/getting-started/modules.html), a useful
    84  abstraction to organize and reuse Terraform configurations.