0
0
TerraformHow-ToBeginner · 3 min read

How to List Workspaces in Terraform: Syntax and Examples

To list all workspaces in Terraform, use the command terraform workspace list. This command shows all existing workspaces and highlights the current active one.
📐

Syntax

The command to list workspaces is simple and has no additional arguments.

  • terraform workspace list: Lists all workspaces in the current Terraform configuration directory.
bash
terraform workspace list
💻

Example

This example shows how to list all workspaces in a Terraform project. The current workspace is marked with an asterisk (*).

bash
terraform workspace list
Output
* default dev staging production
⚠️

Common Pitfalls

Common mistakes when listing workspaces include:

  • Running the command outside a Terraform project directory, which results in an error because no workspace data is found.
  • Confusing terraform workspace list with other commands like terraform workspace show, which only shows the current workspace.

Always run the command inside the directory where your Terraform configuration files are located.

bash
cd /some/other/directory
terraform workspace list

# Wrong: Running outside Terraform project
# Output: Error: No workspace found

cd /path/to/terraform/project
terraform workspace list

# Correct: Lists all workspaces
📊

Quick Reference

CommandDescription
terraform workspace listLists all workspaces in the current Terraform directory
terraform workspace showShows the current active workspace
terraform workspace new Creates a new workspace
terraform workspace select Switches to an existing workspace

Key Takeaways

Use terraform workspace list to see all workspaces in your Terraform project.
Run the command inside the Terraform configuration directory to avoid errors.
The current workspace is marked with an asterisk (*) in the list output.
Do not confuse listing workspaces with showing the current workspace only.
Workspace commands help manage multiple environments in Terraform easily.