Skip to content
Latchkey

terraform console: Usage & Common CI Errors

An interactive REPL for testing expressions, functions, and state values.

terraform console opens a console for evaluating Terraform expressions against your configuration and state - perfect for debugging interpolations and built-in functions.

What it does

terraform console reads expressions and prints their evaluated result, with access to variables, locals, resource attributes from state, and all built-in functions. It is read-only - it never changes infrastructure or state. You can also pipe an expression in for scripted, non-interactive use.

Common usage

Terminal
# Interactive REPL
terraform console
> upper("ci")
> var.region
> aws_instance.web.public_ip

# Non-interactive: pipe an expression in (CI-friendly)
echo 'cidrsubnet("10.0.0.0/16", 8, 2)' | terraform console

Common error in CI: console hangs waiting for stdin

In CI, terraform console with no input blocks forever waiting for an interactive prompt and the job times out. Fix: always feed it an expression non-interactively, e.g. echo 'jsonencode(var.tags)' | terraform console, or read from a heredoc. Run terraform init first so resource references resolve; otherwise references to managed resources return errors or null.

Key options

OptionPurpose
(stdin)Pipe an expression for non-interactive use
-var / -var-fileProvide input variables to evaluate
-state=FILEEvaluate against a specific state file

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →