* website/formatdate: update example The given example was showing HOUR:MONTH instead of HOUR:MINUTE Fixes #22598 * website/import: remove reference to no-longer-working option Users can no longer supply `-config=""` to tell Terraform not to load configuration for import. Fixes #22294 * website/provisioners: `host` is required in connection blocks Fixes #21877 * website/variables: clarify variable definition precedence It was not entirely obvious that a variable could not be assigned multiples times in a single source. Fixes #21682 * website/backend/local: add `workspace_dir` attribute Fixes #21391 * website/output: `sensitive` outputs are redacted in output Fixes #21502 * website/backends: sidebar order tweak It makes sense for backend 'configuration' to appear before 'init'. Fixes #13796 * Revert "website/formatdate: update example" This reverts commit ccd93c86ddd15a21625c0767702ee1cc62e77254.
2.1 KiB
layout | page_title | sidebar_current | description |
---|---|---|---|
docs | Command: output | docs-commands-output | The `terraform output` command is used to extract the value of an output variable from the state file. |
Command: output
The terraform output
command is used to extract the value of
an output variable from the state file.
Usage
Usage: terraform output [options] [NAME]
With no additional arguments, output
will display all the outputs for
the root module. If an output NAME
is specified, only the value of that
output is printed.
The command-line flags are all optional. The list of available flags are:
-json
- If specified, the outputs are formatted as a JSON object, with a key per output. IfNAME
is specified, only the output specified will be returned. This can be piped into tools such asjq
for further processing.-no-color
- If specified, output won't contain any color.-state=path
- Path to the state file. Defaults to "terraform.tfstate". Ignored when remote state is used.
Examples
These examples assume the following Terraform output snippet.
output "lb_address" {
value = "${aws_alb.web.public_dns}"
}
output "instance_ips" {
value = ["${aws_instance.web.*.public_ip}"]
}
output "password" {
sensitive = true
value = ["${var.secret_password}"]
}
To list all outputs:
$ terraform output
Note that outputs with the sensitive
attribute will be redacted:
$ terraform output password
password = <sensitive>
To query for the DNS address of the load balancer:
$ terraform output lb_address
my-app-alb-1657023003.us-east-1.elb.amazonaws.com
To query for all instance IP addresses:
$ terraform output instance_ips
test = [
54.43.114.12,
52.122.13.4,
52.4.116.53
]
To query for a particular value in a list, use -json
and a JSON
command-line parser such as jq.
For example, to query for the first instance's IP address:
$ terraform output -json instance_ips | jq '.value[0]'