Skip to content

Commit 0232b39

Browse files
committed
website: document console command
1 parent a867457 commit 0232b39

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
layout: "docs"
3+
page_title: "Command: console"
4+
sidebar_current: "docs-commands-console"
5+
description: |-
6+
The `terraform console` command creates an interactive console for using [interpolations](/docs/configuration/interpolation.html).
7+
---
8+
9+
# Command: console
10+
11+
The `terraform console` command creates an interactive console for
12+
using [interpolations](/docs/configuration/interpolation.html).
13+
14+
## Usage
15+
16+
Usage: `terraform console [options] [dir]`
17+
18+
This opens an interactive console for experimenting with interpolations.
19+
This is useful for testing interpolations before using them in configurations
20+
as well as interacting with an existing [state](/docs/state/index.html).
21+
22+
If a state file doesn't exist, the console still works and can be used
23+
to experiment with supported interpolation functions. Try entering some basic
24+
math such as `1 + 5` to see.
25+
26+
The `dir` argument can be used to open a console for a specific Terraform
27+
configuration directory. This will load any state from that directory as
28+
well as the configuration. This defaults to the current working directory.
29+
The `console` command does not require Terraform state or configuration
30+
to function.
31+
32+
The command-line flags are all optional. The list of available flags are:
33+
34+
* `-state=path` - Path to the state file. Defaults to "terraform.tfstate".
35+
A state file doesn't need to exist.
36+
37+
## Scripting
38+
39+
The `terraform console` command can be used in non-interactive scripts
40+
by piping newline-separated commands to it. Only the output from the
41+
final command is outputted unless an error occurs earlier.
42+
43+
An example is shown below:
44+
45+
```
46+
$ echo "1 + 5" | terraform console
47+
6
48+
```
49+
50+
## Remote State
51+
52+
The `terraform console `command will read configured state even if it
53+
is [remote](/docs/state/remote/index.html). This is great for scripting
54+
state reading in CI environments or other remote scenarios.
55+
56+
After configuring remote state, run a `terraform remote pull` command
57+
to sync state locally. The `terraform console` command will use this
58+
state for operations.
59+
60+
Because the console currently isn't able to modify state in any way,
61+
this is a one way operation and you don't need to worry about remote
62+
state conflicts in any way.

website/source/layouts/docs.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
<a href="/docs/commands/apply.html">apply</a>
6868
</li>
6969

70+
<li<%= sidebar_current("docs-commands-console") %>>
71+
<a href="/docs/commands/console.html">console</a>
72+
</li>
73+
7074
<li<%= sidebar_current("docs-commands-destroy") %>>
7175
<a href="/docs/commands/destroy.html">destroy</a>
7276
</li>

0 commit comments

Comments
 (0)