github.com/paybyphone/terraform@v0.9.5-0.20170613192930-9706042ddd51/website/docs/commands/output.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Command: output"
     4  sidebar_current: "docs-commands-output"
     5  description: |-
     6    The `terraform output` command is used to extract the value of an output variable from the state file.
     7  ---
     8  
     9  # Command: output
    10  
    11  The `terraform output` command is used to extract the value of
    12  an output variable from the state file.
    13  
    14  ## Usage
    15  
    16  Usage: `terraform output [options] [NAME]`
    17  
    18  With no additional arguments, `output` will display all the outputs for
    19  the root module. If an output `NAME` is specified, only the value of that
    20  output is printed.
    21  
    22  The command-line flags are all optional. The list of available flags are:
    23  
    24  * `-json` - If specified, the outputs are formatted as a JSON object, with
    25      a key per output. If `NAME` is specified, only the output specified will be
    26      returned. This can be piped into tools such as `jq` for further processing.
    27  * `-state=path` - Path to the state file. Defaults to "terraform.tfstate".
    28      Ignored when [remote state](/docs/state/remote.html) is used.
    29  * `-module=module_name` - The module path which has needed output.
    30      By default this is the root path. Other modules can be specified by
    31      a period-separated list. Example: "foo" would reference the module
    32      "foo" but "foo.bar" would reference the "bar" module in the "foo"
    33      module.
    34  
    35  ## Examples
    36  
    37  These examples assume the following Terraform output snippet.
    38  
    39  ```hcl
    40  output "lb_address" {
    41    value = "${aws_alb.web.public_dns}"
    42  }
    43  
    44  output "instance_ips" {
    45    value = ["${aws_instance.web.*.public_ip}"]
    46  }
    47  ```
    48  
    49  To list all outputs:
    50  
    51  ```shell
    52  $ terraform output
    53  ```
    54  
    55  To query for the DNS address of the load balancer:
    56  
    57  ```shell
    58  $ terraform output lb_address
    59  my-app-alb-1657023003.us-east-1.elb.amazonaws.com
    60  ```
    61  
    62  To query for all instance IP addresses:
    63  
    64  ```shell
    65  $ terraform output instance_ips
    66  test = [
    67      54.43.114.12,
    68      52.122.13.4,
    69      52.4.116.53
    70  ]
    71  ```
    72  
    73  To query for a particular value in a list, use `-json` and a JSON
    74  command-line parser such as [jq](https://stedolan.github.io/jq/).
    75  For example, to query for the first instance's IP address:
    76  
    77  ```shell
    78  $ terraform output -json instance_ips | jq '.value[0]'
    79  ```