github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/website/docs/commands/console.html.markdown (about)

     1  ---
     2  layout: "docs"
     3  page_title: "Command: console"
     4  sidebar_current: "docs-commands-console"
     5  description: |-
     6    The `terraform console` command provides an interactive console for
     7    evaluting expressions.
     8  ---
     9  
    10  # Command: console
    11  
    12  The `terraform console` command provides an interactive console for
    13  evaluating [expressions](/docs/configuration/expressions.html).
    14  
    15  ## Usage
    16  
    17  Usage: `terraform console [options] [dir]`
    18  
    19  This command provides an interactive command-line console for evaluating and
    20  experimenting with [expressions](/docs/configuration/expressions.html).
    21  This is useful for testing interpolations before using them in configurations,
    22  and for interacting with any values currently saved in
    23  [state](/docs/state/index.html).
    24  
    25  If the current state is empty or has not yet been created, the console can be
    26  used to experiment with the expression syntax and
    27  [built-in functions](/docs/configuration/functions.html).
    28  
    29  The `dir` argument specifies the directory of the root module to use.
    30  If a path is not specified, the current working directory is used.
    31  
    32  The supported options are:
    33  
    34  * `-state=path` - Path to a local state file. Expressions will be evaluated
    35    using values from this state file. If not specified, the state associated
    36    with the current [workspace](/docs/state/workspaces.html) is used.
    37  
    38  You can close the console with the `exit` command or by pressing Control-C
    39  or Control-D.
    40  
    41  ## Scripting
    42  
    43  The `terraform console` command can be used in non-interactive scripts
    44  by piping newline-separated commands to it. Only the output from the
    45  final command is printed unless an error occurs earlier.
    46  
    47  For example:
    48  
    49  ```shell
    50  $ echo "1 + 5" | terraform console
    51  6
    52  ```
    53  
    54  ## Remote State
    55  
    56  If [remote state](/docs/state/remote.html) is used by the current backend,
    57  Terraform will read the state for the current workspace from the backend
    58  before evaluating any expressions.