2016-11-14 07:57:28 +01:00
|
|
|
---
|
|
|
|
layout: "docs"
|
|
|
|
page_title: "Command: console"
|
|
|
|
sidebar_current: "docs-commands-console"
|
|
|
|
description: |-
|
2018-05-14 01:59:18 +02:00
|
|
|
The `terraform console` command provides an interactive console for
|
|
|
|
evaluting expressions.
|
2016-11-14 07:57:28 +01:00
|
|
|
---
|
|
|
|
|
|
|
|
# Command: console
|
|
|
|
|
2018-05-14 01:59:18 +02:00
|
|
|
The `terraform console` command provides an interactive console for
|
|
|
|
evaluating [expressions](/docs/configuration/expressions.html).
|
2016-11-14 07:57:28 +01:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
Usage: `terraform console [options] [dir]`
|
|
|
|
|
2018-05-14 01:59:18 +02:00
|
|
|
This command provides an interative command-line console for evaluating and
|
|
|
|
experimenting with [expressions](/docs/configuration/expressions.html).
|
|
|
|
This is useful for testing interpolations before using them in configurations,
|
|
|
|
and for interacting with any values currently saved in
|
|
|
|
[state](/docs/state/index.html).
|
2016-11-14 07:57:28 +01:00
|
|
|
|
2018-05-14 01:59:18 +02:00
|
|
|
If the current state is empty or has not yet been created, the console can be
|
|
|
|
used to experiment with the expression syntax and
|
|
|
|
[built-in functions](/docs/configuration/functions.html).
|
2016-11-14 07:57:28 +01:00
|
|
|
|
2018-05-14 01:59:18 +02:00
|
|
|
The `dir` argument specifies the directory of the root module to use.
|
|
|
|
If a path is not specified, the current working directory is used.
|
2016-11-14 07:57:28 +01:00
|
|
|
|
2018-05-14 01:59:18 +02:00
|
|
|
The supported options are:
|
2016-11-14 07:57:28 +01:00
|
|
|
|
2018-05-14 01:59:18 +02:00
|
|
|
* `-state=path` - Path to a local state file. Expressions will be evaluated
|
|
|
|
using values from this state file. If not specified, the state associated
|
|
|
|
with the current [workspace](/docs/state/workspaces.html) is used.
|
2016-11-14 07:57:28 +01:00
|
|
|
|
2018-05-14 01:59:18 +02:00
|
|
|
You can close the console with the `exit` command or by pressing Control-C
|
2016-11-17 10:23:50 +01:00
|
|
|
or Control-D.
|
|
|
|
|
2016-11-14 07:57:28 +01:00
|
|
|
## Scripting
|
|
|
|
|
|
|
|
The `terraform console` command can be used in non-interactive scripts
|
|
|
|
by piping newline-separated commands to it. Only the output from the
|
2018-05-14 01:59:18 +02:00
|
|
|
final command is printed unless an error occurs earlier.
|
2016-11-14 07:57:28 +01:00
|
|
|
|
2018-05-14 01:59:18 +02:00
|
|
|
For example:
|
2016-11-14 07:57:28 +01:00
|
|
|
|
2017-04-05 17:29:27 +02:00
|
|
|
```shell
|
2016-11-14 07:57:28 +01:00
|
|
|
$ echo "1 + 5" | terraform console
|
|
|
|
6
|
|
|
|
```
|
|
|
|
|
|
|
|
## Remote State
|
|
|
|
|
2018-05-14 01:59:18 +02:00
|
|
|
If [remote state](/docs/state/remote.html) is used by the current backend,
|
|
|
|
Terraform will read the state for the current workspace from the backend
|
|
|
|
before evaluating any expressions.
|