Add more output grammar and CLI examples
This commit is contained in:
parent
e37dbefd90
commit
988b0325a1
|
@ -15,8 +15,9 @@ an output variable from the state file.
|
|||
|
||||
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.
|
||||
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:
|
||||
|
||||
|
@ -30,3 +31,49 @@ The command-line flags are all optional. The list of available flags are:
|
|||
a period-separated list. Example: "foo" would reference the module
|
||||
"foo" but "foo.bar" would reference the "bar" module in the "foo"
|
||||
module.
|
||||
|
||||
## Examples
|
||||
|
||||
These examples assume the following Terraform output snippet.
|
||||
|
||||
```ruby
|
||||
output "lb_address" {
|
||||
value = "${aws_alb.web.public_dns}"
|
||||
}
|
||||
|
||||
output "instance_ips" {
|
||||
value = "${aws_instance.web.*.public_ip}"
|
||||
}
|
||||
```
|
||||
|
||||
To list all outputs:
|
||||
|
||||
```text
|
||||
$ terraform output
|
||||
```
|
||||
|
||||
To query for the DNS address of the load balancer:
|
||||
|
||||
```text
|
||||
$ terraform output lb_address
|
||||
my-app-alb-1657023003.us-east-1.elb.amazonaws.com
|
||||
```
|
||||
|
||||
To query for all instance IP addresses:
|
||||
|
||||
```text
|
||||
$ 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](https://stedolan.github.io/jq/).
|
||||
For example, to query for the first instance's IP address:
|
||||
|
||||
```text
|
||||
$ terraform output -json instance_ips | jq '.value[0]'
|
||||
```
|
||||
|
|
|
@ -16,21 +16,31 @@ is covered in more detail in the
|
|||
This page covers configuration syntax for outputs.
|
||||
|
||||
Terraform knows a lot about the infrastructure it manages.
|
||||
Most resources have a handful or even a dozen or more attributes
|
||||
associated with it. Outputs are a way to easily extract
|
||||
information.
|
||||
Most resources have attributes associated with them, and
|
||||
outputs are a way to easily extract and query that information.
|
||||
|
||||
This page assumes you're familiar with the
|
||||
This page assumes you are familiar with the
|
||||
[configuration syntax](/docs/configuration/syntax.html)
|
||||
already.
|
||||
|
||||
## Example
|
||||
|
||||
An output configuration looks like the following:
|
||||
A simple output configuration looks like the following:
|
||||
|
||||
```
|
||||
```ruby
|
||||
output "address" {
|
||||
value = "${aws_instance.web.public_dns}"
|
||||
value = "${aws_instance.db.public_dns}"
|
||||
}
|
||||
```
|
||||
|
||||
This will output a string value corresponding to the public
|
||||
DNS address of the Terraform-defined AWS instance named "db". It
|
||||
is possible to export complex data types like maps and strings as
|
||||
well:
|
||||
|
||||
```ruby
|
||||
output "addresses" {
|
||||
value = ["${aws_instance.web.*.public_dns}"]
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -54,7 +64,7 @@ These are the parameters that can be set:
|
|||
|
||||
The full syntax is:
|
||||
|
||||
```
|
||||
```ruby
|
||||
output NAME {
|
||||
value = VALUE
|
||||
}
|
||||
|
@ -65,7 +75,7 @@ output NAME {
|
|||
Outputs can be marked as containing sensitive material by setting the
|
||||
`sensitive` attribute to `true`, like this:
|
||||
|
||||
```
|
||||
```ruby
|
||||
output "sensitive" {
|
||||
sensitive = true
|
||||
value = VALUE
|
||||
|
|
Loading…
Reference in New Issue