github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/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 * `-no-color` - If specified, output won't contain any color. 28 * `-state=path` - Path to the state file. Defaults to "terraform.tfstate". 29 Ignored when [remote state](/docs/state/remote.html) is used. 30 31 ## Examples 32 33 These examples assume the following Terraform output snippet. 34 35 ```hcl 36 output "lb_address" { 37 value = "${aws_alb.web.public_dns}" 38 } 39 40 output "instance_ips" { 41 value = ["${aws_instance.web.*.public_ip}"] 42 } 43 44 output "password" { 45 sensitive = true 46 value = ["${var.secret_password}"] 47 } 48 ``` 49 50 To list all outputs: 51 52 ```shell 53 $ terraform output 54 ``` 55 56 Note that outputs with the `sensitive` attribute will be redacted: 57 ```shell 58 $ terraform output password 59 password = <sensitive> 60 ``` 61 62 To query for the DNS address of the load balancer: 63 64 ```shell 65 $ terraform output lb_address 66 my-app-alb-1657023003.us-east-1.elb.amazonaws.com 67 ``` 68 69 To query for all instance IP addresses: 70 71 ```shell 72 $ terraform output instance_ips 73 test = [ 74 54.43.114.12, 75 52.122.13.4, 76 52.4.116.53 77 ] 78 ``` 79 80 To query for a particular value in a list, use `-json` and a JSON 81 command-line parser such as [jq](https://stedolan.github.io/jq/). 82 For example, to query for the first instance's IP address: 83 84 ```shell 85 $ terraform output -json instance_ips | jq '.value[0]' 86 ```