Exploring Terraform Console - An Interactive Way to Work with Terraform

By Łukasz Kallas
Picture of the author
Published on
terraform image

When working with Terraform, especially on large projects, it can be beneficial to evaluate expressions and explore resources interactively. Terraform Console provides an interactive shell that lets us experiment with Terraform code, inspect resource attributes, and test interpolation syntax without having to apply changes.

What is Terraform Console?

Terraform Console is a built-in REPL (Read-Eval-Print Loop) tool for Terraform. It allows you to:

  • Evaluate expressions
  • Access and manipulate Terraform variables and outputs
  • Inspect and debug your Terraform configurations
  • Explore resource attributes and outputs without applying any changes

This tool can be especially useful during the development and debugging stages of your infrastructure as code workflow.

Why Use Terraform Console?

  • Experimentation: Quickly test and refine expressions, functions, and configurations.
  • Debugging: Check the current values of variables and outputs, helping you troubleshoot issues.
  • Learning: A great way to explore and understand how different components and functions in Terraform work together.

How to Use Terraform Console

To start the Terraform Console, navigate to your Terraform configuration directory and run the command:

terraform console

Example Usage

Once in the console, you can evaluate different expressions and functions. Here are a few examples:

Basic Arithmetic
> 5 + 3
8
Functions
> "Hello, ${upper("world")}!"
"Hello, WORLD!"
Accessing Resource Attributes

If you have a defined resource in your configuration, you can access its attributes:

> aws_instance.example.private_ip
"192.168.1.4"

Stay Tuned

Want to learn?
The best articles, links and news related to software development delivered once a week to your inbox.