-
Notifications
You must be signed in to change notification settings - Fork 87
PluginTerraform
Display Terraform/OpenTofu workspace with production warnings and pending changes indicator.
production
dev
staging*
default
| Property | Value |
|---|---|
| Platform | macOS, Linux, FreeBSD |
| Dependencies |
terraform or tofu (OpenTofu) |
| Content Type | dynamic |
| Presence | conditional (hidden outside Terraform directories) |
# Add to your tmux configuration
set -g @powerkit_plugins "terraform"
# Optional: Add workspace selector keybinding
set -g @powerkit_plugin_terraform_keybinding_workspace ""
# Reload tmux configuration
tmux source-file ~/.tmux.confset -g @powerkit_plugins "terraform"
# Tool selection (auto detects terraform or tofu)
set -g @powerkit_plugin_terraform_tool "auto"
# Display options
set -g @powerkit_plugin_terraform_show_pending "true"
# Production warning
set -g @powerkit_plugin_terraform_warn_on_prod "true"
set -g @powerkit_plugin_terraform_prod_keywords "prod,production,prd"
# Icons
set -g @powerkit_plugin_terraform_icon ""
set -g @powerkit_plugin_terraform_icon_pending ""
# Keybindings
set -g @powerkit_plugin_terraform_keybinding_workspace ""
set -g @powerkit_plugin_terraform_popup_width "60%"
set -g @powerkit_plugin_terraform_popup_height "60%"
# Cache
set -g @powerkit_plugin_terraform_cache_ttl "5"| Option | Type | Default | Description |
|---|---|---|---|
@powerkit_plugin_terraform_tool |
enum | auto |
Preferred tool: auto, terraform, or tofu
|
@powerkit_plugin_terraform_show_pending |
bool | true |
Show indicator for pending changes |
@powerkit_plugin_terraform_warn_on_prod |
bool | true |
Warn when in production workspace |
@powerkit_plugin_terraform_prod_keywords |
string | prod,production,prd |
Comma-separated production keywords |
@powerkit_plugin_terraform_icon |
icon | |
Default Terraform icon |
@powerkit_plugin_terraform_icon_pending |
icon | |
Pending changes icon |
@powerkit_plugin_terraform_keybinding_workspace |
string | `` | Keybinding for workspace selector |
@powerkit_plugin_terraform_popup_width |
string | 60% |
Workspace selector popup width |
@powerkit_plugin_terraform_popup_height |
string | 60% |
Workspace selector popup height |
@powerkit_plugin_terraform_cache_ttl |
number | 5 |
Cache duration in seconds |
| State | Condition |
|---|---|
active |
In Terraform directory, workspace detected |
degraded |
In Terraform directory with pending changes |
inactive |
Not in Terraform directory |
This plugin uses plugin_should_be_active() to check if the current pane is in a Terraform directory before returning cached data. This ensures the plugin disappears immediately when switching to a non-Terraform directory, rather than showing stale data from the previous context.
| Level | Condition |
|---|---|
ok |
Non-production workspace, no pending changes |
warning |
Pending changes detected |
error |
Production workspace (based on keywords) |
| Context | Description |
|---|---|
none |
Not in Terraform directory |
production |
In production workspace |
production_pending |
In production with pending changes |
default |
Using default workspace |
default_pending |
Default workspace with pending changes |
staging |
In staging workspace |
staging_pending |
Staging workspace with pending changes |
development |
In development workspace |
development_pending |
Development workspace with pending changes |
custom |
Custom workspace name |
custom_pending |
Custom workspace with pending changes |
set -g @powerkit_plugins "terraform"set -g @powerkit_plugins "terraform"
set -g @powerkit_plugin_terraform_tool "tofu"set -g @powerkit_plugins "terraform"
set -g @powerkit_plugin_terraform_keybinding_workspace "C-w"set -g @powerkit_plugins "terraform"
set -g @powerkit_plugin_terraform_prod_keywords "prod,production,live,prd"set -g @powerkit_plugins "terraform"
set -g @powerkit_plugin_terraform_show_only_in_dir "true"set -g @powerkit_plugins "terraform"
set -g @powerkit_plugin_terraform_show_pending "false"The plugin detects Terraform workspaces using multiple methods:
-
Environment file (fastest, no command execution)
- Reads
.terraform/environment
- Reads
-
Tool command (fallback)
terraform workspace showtofu workspace show
-
Default (if nothing found)
- Returns "default"
A directory is considered a Terraform directory if it contains:
-
.terraform/directory (initialized project) -
*.tffiles (Terraform configuration files)
The plugin detects pending changes by checking for:
-
tfplanfile in current directory -
tfplanfile in.terraform/directory
These files are created by terraform plan -out=tfplan.
When warn_on_prod is enabled, the plugin:
- Checks workspace name against
prod_keywords(case-insensitive) - Sets health to
errorif match found - Displays workspace in error color (red by default)
This helps prevent accidental modifications to production infrastructure.
OpenTofu is a fork of Terraform. The plugin supports both:
| Tool | Command | Detection |
|---|---|---|
| Terraform | terraform |
Checked first if tool = terraform
|
| OpenTofu | tofu |
Checked first if tool = tofu
|
The plugin automatically falls back to the other tool if the preferred one isn't available.
| Action | Default Key | Description |
|---|---|---|
| Workspace Selector | (not bound) | Interactive workspace selector |
The workspace selector uses tmux display-menu (not popup) to show and switch between available workspaces.
| Condition | Output |
|---|---|
show_workspace = true |
workspace (e.g., production) |
show_workspace = true + pending |
workspace* (e.g., staging*) |
show_workspace = false |
TF |
-
Verify you're in a Terraform directory:
ls .terraform/ ls *.tf -
Check tool availability:
which terraform # or which tofu -
Verify workspace:
terraform workspace show # or tofu workspace show -
Test plugin directly:
POWERKIT_ROOT="/path/to/tmux-powerkit" ./bin/powerkit-plugin terraform
The plugin reads from .terraform/environment file. If this is out of sync:
# Remove environment file
rm .terraform/environment
# Reinitialize
terraform init
# Select workspace
terraform workspace select <name>-
Check workspace name matches keywords:
terraform workspace show
-
Verify keywords configuration:
tmux show-options -g | grep terraform_prod_keywords -
Keywords are case-insensitive partial matches:
-
prodmatches:prod,production,prod-us-east -
prdmatches:prd,prd-staging
-
-
Verify keybinding is set:
tmux show-options -g | grep terraform_keybinding -
Check for keybinding conflicts:
tmux list-keys | grep "C-w"
-
Test helper script manually:
bash ~/.config/tmux/plugins/tmux-powerkit/src/helpers/terraform_workspace_selector.sh select
The plugin looks for tfplan files. If always showing:
-
Check for leftover plan files:
find . -name "tfplan"
-
Remove old plan files:
rm tfplan rm .terraform/tfplan
-
Or disable pending detection:
set -g @powerkit_plugin_terraform_show_pending "false"
Always enable production warnings:
set -g @powerkit_plugin_terraform_warn_on_prod "true"
set -g @powerkit_plugin_terraform_prod_keywords "prod,production,live"This provides visual confirmation when working in production environments.
Use workspace selector for quick switching:
set -g @powerkit_plugin_terraform_keybinding_workspace "C-w"Then:
- Navigate to Terraform directory
- Press
prefix + C-w - Select workspace from menu
- Plugin updates automatically
For projects with many environments, customize keywords:
set -g @powerkit_plugin_terraform_prod_keywords "prod,production,live,prd"This ensures all production-like environments trigger warnings.
The plugin uses src/helpers/terraform_workspace_selector.sh for workspace management:
# List workspaces
bash ~/.config/tmux/plugins/tmux-powerkit/src/helpers/terraform_workspace_selector.sh list
# Select workspace
bash ~/.config/tmux/plugins/tmux-powerkit/src/helpers/terraform_workspace_selector.sh select- PluginKubernetes - Kubernetes context and namespace
- PluginCloud - Cloud provider profile
- PluginGit - Git repository status