github.com/muratcelep/terraform@v1.1.0-beta2-not-internal-4/website/docs/cli/commands/output.html.md (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  * `-raw` - If specified, Terraform will convert the specified output value to a
    28      string and print that string directly to the output, without any special
    29      formatting. This can be convenient when working with shell scripts, but
    30      it only supports string, number, and boolean values. Use `-json` instead
    31      for processing complex data types.
    32  * `-no-color` - If specified, output won't contain any color.
    33  * `-state=path` - Path to the state file. Defaults to "terraform.tfstate".
    34      Ignored when [remote state](/docs/language/state/remote.html) is used.
    35  
    36  -> **Note:** When using the `-json` or `-raw` command-line flag, any sensitive
    37  values in Terraform state will be displayed in plain text. For more information,
    38  see [Sensitive Data in State](/docs/language/state/sensitive-data.html).
    39  
    40  ## Examples
    41  
    42  These examples assume the following Terraform output snippet.
    43  
    44  ```hcl
    45  output "instance_ips" {
    46    value = aws_instance.web.*.public_ip
    47  }
    48  
    49  output "lb_address" {
    50    value = aws_alb.web.public_dns
    51  }
    52  
    53  output "password" {
    54    sensitive = true
    55    value = var.secret_password
    56  }
    57  ```
    58  
    59  To list all outputs:
    60  
    61  ```shellsession
    62  $ terraform output
    63  instance_ips = [
    64    "54.43.114.12",
    65    "52.122.13.4",
    66    "52.4.116.53"
    67  ]
    68  lb_address = "my-app-alb-1657023003.us-east-1.elb.amazonaws.com"
    69  password = <sensitive>
    70  ```
    71  
    72  Note that outputs with the `sensitive` attribute will be redacted:
    73  
    74  ```shellsession
    75  $ terraform output password
    76  password = <sensitive>
    77  ```
    78  
    79  To query for the DNS address of the load balancer:
    80  
    81  ```shellsession
    82  $ terraform output lb_address
    83  "my-app-alb-1657023003.us-east-1.elb.amazonaws.com"
    84  ```
    85  
    86  To query for all instance IP addresses:
    87  
    88  ```shellsession
    89  $ terraform output instance_ips
    90  instance_ips = [
    91    "54.43.114.12",
    92    "52.122.13.4",
    93    "52.4.116.53"
    94  ]
    95  ```
    96  
    97  ## Use in automation
    98  
    99  The `terraform output` command by default displays in a human-readable format,
   100  which can change over time to improve clarity.
   101  
   102  For scripting and automation, use `-json` to produce the stable JSON format.
   103  You can parse the output using a JSON command-line parser such as
   104  [jq](https://stedolan.github.io/jq/):
   105  
   106  ```shellsession
   107  $ terraform output -json instance_ips | jq -r '.[0]'
   108  54.43.114.12
   109  ```
   110  
   111  For the common case of directly using a string value in a shell script, you
   112  can use `-raw` instead, which will print the string directly with no extra
   113  escaping or whitespace.
   114  
   115  ```shellsession
   116  $ terraform output -raw lb_address
   117  my-app-alb-1657023003.us-east-1.elb.amazonaws.com
   118  ```
   119  
   120  The `-raw` option works only with values that Terraform can automatically
   121  convert to strings. Use `-json` instead, possibly combined with `jq`, to
   122  work with complex-typed values such as objects.
   123  
   124  Terraform strings are sequences of Unicode characters rather than raw bytes,
   125  so the `-raw` output will be UTF-8 encoded when it contains non-ASCII
   126  characters. If you need a different character encoding, use a separate command
   127  such as `iconv` to transcode Terraform's raw output.