New advertisers: 50% off your first month with code FIRSTMONTHSee slots

Terraform Cloud plugin that inspects runs, logs, and plan JSON and blocks unreviewed applies.

version
1.7.13
GitHub stars
60
View on GitHub

What it does

  • Adds the terraform-ops agent, six tfc-* skills, and a validate-terraform-apply.sh PreToolUse hook on Bash
  • Covers run listing, run status, run logs, and plan JSON analysis across configured TFC workspaces
  • Enforces a block on terraform apply unless it applies a saved plan file, including auto-approve variants
  • Designed for teams using Terraform Cloud who need run history, debugging logs, and plan review from Claude Code

Terraform and Terraform Cloud - infrastructure as code

Add marketplace

/plugin marketplace add laurigates/claude-plugins

Run it inside Claude Code once, then install the plugin below.

Install

/plugin install terraform-plugin@laurigates-claude-plugins

Run it inside Claude Code after adding the marketplace.

Files

Discovered from source

Infrastructure Terraform

Expert knowledge for Infrastructure as Code using Terraform with focus on declarative HCL, state management, and resilient infrastructure.

When to Use This Skill

Use this skill when...Use a tfc-* sibling instead when...
Writing or modifying Terraform HCL configuration locallyInspecting Terraform Cloud run state via API (tfc-run-status)
Running terraform init/plan/apply/destroy against a backendReading TFC plan/apply log streams (tfc-run-logs)
Designing module structure, providers, or remote backendsAnalyzing structured plan JSON from a TFC run (tfc-plan-json)
Debugging local state, drift, or import workflowsListing or filtering TFC run history (tfc-list-runs, tfc-workspace-runs)

Core Expertise

Terraform & IaC

  • Declarative Infrastructure: Clean, modular, and reusable HCL code
  • State Management: Protecting and managing Terraform state with remote backends
  • Providers & Modules: Leveraging community and custom providers/modules
  • Execution Lifecycle: Mastering the plan -> review -> apply workflow

Infrastructure Provisioning Process

  1. Plan First: Always generate terraform plan and review carefully before changes
  2. Modularize: Break down infrastructure into reusable and composable modules
  3. Secure State: Use remote backends with locking to protect state file
  4. Parameterize: Use variables and outputs for flexible and configurable infrastructure
  5. Destroy with Caution: Double-check plan before running terraform destroy

Essential Commands

# Core workflow
terraform init                   # Initialize working directory
terraform plan                   # Generate execution plan
terraform apply                  # Apply changes
terraform destroy               # Destroy infrastructure

# State management
terraform state list            # List all resources
terraform state show <resource> # Show specific resource
terraform state pull > backup.tfstate  # Backup state

# Validation and formatting
terraform validate              # Validate configuration
terraform fmt -recursive        # Format all files recursively
terraform fmt path/to/dir       # Format specific directory
terraform graph | dot -Tsvg > graph.svg  # Dependency graph

# Working with directories (use -chdir to stay in repo root)
terraform -chdir=gcp fmt        # Format files in gcp/ directory
terraform -chdir=gcp validate   # Validate gcp/ configuration
terraform -chdir=gcp plan       # Plan from specific directory
terraform -chdir=modules/vpc init  # Init module directory

# Debugging
export TF_LOG=DEBUG             # Enable debug logging
terraform plan -out=tfplan      # Save plan for review
terraform show tfplan           # View saved plan

Best Practices

Module Structure

module "vpc" {
  source  = "./modules/vpc"
  version = "1.0.0"

  vpc_cidr = var.vpc_cidr
  environment = var.environment
}

output "vpc_id" {
  value = module.vpc.vpc_id
}

Variable Configuration

variable "environment" {
  description = "Environment name"
  type        = string
  validation {
    condition     = contains(["dev", "staging", "prod"], var.environment)
    error_message = "Environment must be dev, staging, or prod."
  }
}

Remote State Backend

terraform {
  backend "s3" {
    bucket         = "my-terraform-state"
    key            = "prod/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = true
    dynamodb_table = "terraform-locks"
  }
}

Provider Configuration

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
  required_version = ">= 1.5"
}

Key Debugging Techniques

State Debugging

# State inspection
terraform state list
terraform state show aws_instance.web

# State recovery
terraform refresh
terraform plan -refresh-only
terraform import aws_instance.existing i-1234567890

Error Resolution

# Provider errors
terraform init -upgrade
terraform init -reconfigure

# Resource conflicts
terraform taint aws_instance.broken
terraform apply -target=aws_instance.web

Agentic Optimizations

ContextCommand
Format directoryterraform -chdir=path/to/dir fmt
Check format (CI)terraform fmt -check -recursive
Validate configterraform -chdir=path/to/dir validate
Compact planterraform plan -compact-warnings
JSON plan outputterraform plan -out=plan.tfplan && terraform show -json plan.tfplan
List resourcesterraform state list

Quick Reference

FlagDescription
-chdir=DIRChange to DIR before running command
-recursiveProcess directories recursively
-checkCheck formatting without changes (CI)
-compact-warningsShow warnings in compact form
-jsonOutput in JSON format
-out=FILESave plan to file
-target=RESOURCETarget specific resource
-refresh-onlyOnly refresh state, no changes

For detailed debugging patterns, advanced module design, CI/CD integration, and troubleshooting strategies, see REFERENCE.md.

Readme

Terraform Plugin

Terraform Cloud (TFC) automation for infrastructure management - list runs, check status, fetch logs, and analyze plan JSON output.

Overview

This plugin provides comprehensive Terraform Cloud API automation for monitoring and analyzing infrastructure runs, plans, and applies. Work with TFC workspaces, retrieve logs, analyze plan changes, and track run status directly from Claude Code.

Skills

SkillDescription
tfc-run-logsRetrieve plan and apply logs from Terraform Cloud runs
tfc-workspace-runsConvenience wrapper for listing runs in configured workspaces
tfc-list-runsList and filter runs from Terraform Cloud workspaces
tfc-run-statusQuick status check for TFC runs with resource changes and actions
tfc-plan-jsonDownload and analyze structured Terraform plan JSON output

Hooks

validate-terraform-apply.sh is a PreToolUse hook on the Bash tool that gates an unreviewed apply.

CommandVerdict
terraform applyBlocked — nothing was reviewed
terraform apply -auto-approve, including the quoted spellings and alongside a plan fileBlocked
terraform apply -refresh=false, terraform apply 2>&1 | tee logBlocked — no plan file anywhere in the command
timeout 300 terraform apply, env -i terraform apply, for d in …; do terraform apply; doneBlocked — the wrapper and the loop keyword do not hide the program
terraform apply tfplanAllowed — applies exactly the saved plan
A quoted argument, heredoc body, or comment carrying the phraseAllowed
bash -c "terraform apply", echo "$(terraform apply)"Blocked — that text is shell, not data

The hook decides command position with ast-grep --lang bash (tree-sitter-bash), the classifier hooks-plugin/hooks/bash-antipatterns.sh adopted in #2008. Each command node of the Bash call is examined on its own, so a heredoc body is never a command, a redirection's fd digit is never an argument, a do/then keyword is never glued to the program name, and any wrapper — sudo, timeout, nice, stdbuf, xargs, uv run — is just the front of the same node. A PR body or search query quoting terraform apply executes nothing and is not gated (#2506). The one thing tree-sitter cannot see into is a shell invoker's script argument, so bash -c "…", sh -c '…' and eval "…" have their quoted arguments re-parsed as shell.

A program name assembled from an expansion — A='terraform apply -auto-approve'; $A — carries no terraform token and is not caught. Neither the pre-#2506 regex nor any later version caught it; the gate stops the unreviewed apply written by habit, not one written to evade it.

Where ast-grep is not installed the hook does not fire at all. It fails open, exactly as bash-antipatterns.sh does, because a PreToolUse hook that hard-fails without its parser breaks every Bash call. Install ast-grep (brew install ast-grep, cargo install ast-grep) for the gate to be in effect.

Quotes are removed rather than masked, because the shell removes them: terraform apply "-auto-approve" really delivers -auto-approve to the process, and is blocked. A plan file is a positional operand carrying no =, not consumed as a preceding bare flag's value (so -var foo=bar and -target aws_x.y do not count as one), and named literally — a $VAR, $(…) or backtick operand cannot be resolved here, could expand to -auto-approve, and is treated as an unreviewed apply.

Prerequisites

All skills require a Terraform Cloud API token:

export TFE_TOKEN="your-api-token"        # User or team token (not organization token)
export TFE_ADDRESS="app.terraform.io"    # Optional, defaults to app.terraform.io

Common Use Cases

Check Workspace Runs

List recent runs for a workspace:

# Using tfc-workspace-runs skill
# Supports: github, sentry, gcp, onelogin, twingate

Get Run Logs

Retrieve plan and apply logs for debugging:

# Using tfc-run-logs skill
# Fetches both plan and apply logs for a run ID

Analyze Plan Changes

Download and analyze structured plan JSON:

# Using tfc-plan-json skill
# Get detailed resource change information

Monitor Run Status

Quick status check with resource counts:

# Using tfc-run-status skill
# Shows status, resource changes, and available actions

Filter Runs

List runs by status, operation type, or date:

# Using tfc-list-runs skill
# Filter by: status, status group, operation, source, timeframe

Installation

/plugin install terraform-plugin@laurigates-claude-plugins

License

MIT

Details

Marketplace
laurigates/claude-plugins
Source
terraform-plugin
Author
Lauri Gates
Category
Infrastructure
License
MIT
Keywords
terraform, infrastructure, iac, tfc
Listed since
Apr 7, 2026

More from laurigates/claude-plugins

All 52

Similar to terraform-plugin

More DevOps & Cloud