|
| 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. |
0 commit comments