CtrlK
BlogDocsLog inGet started
Tessl Logo

pantheon-ai/terraform-validator

Comprehensive toolkit for validating, linting, testing, and automating Terraform configurations and HCL files. Use this skill when working with Terraform files (.tf, .tfvars), validating infrastructure-as-code, debugging Terraform configurations, performing dry-run testing with terraform plan, or working with custom providers and modules.

Overall
score

100%

Does it follow best practices?

Validation for skill structure

Overview
Skills
Evals
Files
name:
terraform-validator
description:
Comprehensive toolkit for validating, linting, testing, and automating Terraform configurations and HCL files. Use this skill when working with Terraform files (.tf, .tfvars), validating infrastructure-as-code, debugging Terraform configurations, performing dry-run testing with terraform plan, or working with custom providers and modules.

Terraform Validator

Comprehensive toolkit for validating, linting, and testing Terraform configurations with automated workflows for syntax validation, security scanning, and intelligent documentation lookup.

Validation Workflow

Execute these steps in order. Steps marked Required must not be skipped.

StepActionRequired
1Run bash scripts/extract_tf_info_wrapper.sh <path>Required
2Context7 lookup for all providers (explicit and implicit); WebSearch fallback if not foundRequired
3Read references/security_checklist.mdRequired
4Read references/best_practices.mdRequired
5Run terraform fmtRequired
6Run tflint (or note as skipped if unavailable)Recommended
7Run terraform init (if not initialized)Required
8Run terraform validateRequired
9Run bash scripts/run_checkov.sh <path>Required
10Cross-reference findings with security_checklist.md sectionsRequired
11Generate report citing reference filesRequired

Steps 3–4 (reading reference files) must be completed before running security scans. The reference files contain remediation patterns that must be cited in the report.

External Documentation

ToolDocumentation
Terraformdeveloper.hashicorp.com/terraform
TFLintgithub.com/terraform-linters/tflint
Checkovcheckov.io
Trivyaquasecurity.github.io/trivy

Scripts Reference

Use these wrapper scripts instead of calling tools directly:

ScriptPurposeCommand
extract_tf_info_wrapper.shParse Terraform files for providers/modules (auto-handles python-hcl2 via temporary venv)bash scripts/extract_tf_info_wrapper.sh <path>
extract_tf_info.pyCore parser (requires python-hcl2)Use wrapper instead
run_checkov.shWrapper for Checkov scans with enhanced outputbash scripts/run_checkov.sh <path>
install_checkov.shInstall Checkov in isolated venvbash scripts/install_checkov.sh install

Provider Documentation Lookup

Detection and lookup workflow:

1. Run extract_tf_info_wrapper.sh to get provider list
2. Collect explicit providers from "providers" array
3. Detect implicit providers from resource type prefixes:
   - Extract prefix (e.g., "random" from "random_id")
   - Common implicit: random, null, local, tls, time, archive, http, external
4. For each provider (explicit + implicit):
   a. Call: mcp__context7__resolve-library-id with "terraform-provider-{name}"
   b. Call: mcp__context7__get-library-docs with the resolved ID
   c. If Context7 fails: WebSearch("terraform-provider-{name} hashicorp documentation site:registry.terraform.io")
5. Include relevant provider guidance in validation report

Note: HashiCorp utility providers (random, null, local, time, tls, archive, external, http) are often not indexed in Context7 — use WebSearch directly for these.

Required Reference Files

Read these files at the specified points in the workflow:

WhenReference FileContent
Before security scanreferences/security_checklist.mdSecurity checks, Checkov/Trivy usage, remediation patterns
During validationreferences/best_practices.mdProject structure, naming conventions, module design, state management
When errors occurreferences/common_errors.mdError database with causes and solutions
If Terraform >= 1.10references/advanced_features.mdEphemeral values (1.10+), Actions (1.14+), List Resources (1.14+)

Quick Reference Commands

Format and Lint

# Check formatting (dry-run)
terraform fmt -check -recursive .

# Apply formatting
terraform fmt -recursive .

# Run tflint
tflint --init              # Install plugins
tflint --recursive         # Lint all modules
tflint --format compact    # Compact output

Validate Configuration

terraform init             # Downloads providers and modules
terraform validate         # Validate syntax
terraform validate -json   # JSON output

Security Scanning

# Use the wrapper script
bash scripts/run_checkov.sh ./terraform

# With specific options
bash scripts/run_checkov.sh -f json ./terraform
bash scripts/run_checkov.sh --compact ./terraform

Dry-Run Testing

terraform plan                               # Generate execution plan
terraform plan -out=tfplan                   # Save plan to file
terraform plan -var-file="production.tfvars" # Plan with var file
terraform plan -target=aws_instance.example  # Plan specific resource

Plan output symbols: + create · - destroy · ~ modify · -/+ replace

Security Finding Reports

When reporting security findings from Checkov/Trivy scans, cross-reference specific sections from security_checklist.md. The security checklist contains:

  • Checkov check ID to section mappings
  • Remediation patterns with code examples
  • Severity guidelines

Report Template for Security Findings

### Security Issue: [Check ID]

**Finding:** [Description from checkov]
**Resource:** [Resource name and file:line]
**Severity:** [HIGH/MEDIUM/LOW]

**Reference:** security_checklist.md - "[Section Name]" (see relevant section for check ID)

**Remediation Pattern:**
[Copy relevant code example from security_checklist.md]

**Recommended Fix:**
[Specific fix for this configuration]

Example Cross-Referenced Report

### Security Issue: CKV_AWS_24

**Finding:** Security group allows SSH from 0.0.0.0/0
**Resource:** aws_security_group.web (main.tf:47-79)
**Severity:** HIGH

**Reference:** security_checklist.md - "Overly Permissive Security Groups"

**Remediation Pattern (from reference):**
```hcl
variable "admin_cidr" {
  description = "CIDR block for admin access"
  type        = string
}

resource "aws_security_group" "app" {
  ingress {
    description = "SSH from admin network only"
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = [var.admin_cidr]
  }
}

Recommended Fix: Replace cidr_blocks = ["0.0.0.0/0"] with a variable or specific CIDR range.

## Handling Missing Tools

When a validation tool is not installed:
  1. Inform user what is missing and why it's needed
  2. Provide the installation command
  3. Ask: "Would you like me to install [tool] and continue?"
  4. If yes: run installation and rerun the validation step
  5. If no: note as skipped in report, continue with available tools
**If checkov is missing:** Ask to install via `bash scripts/install_checkov.sh install`, then rerun security scan.

**If tflint is missing:** Ask to install (`brew install tflint` on macOS or equivalent), note as skipped if declined.

**If python-hcl2 is missing:** `extract_tf_info_wrapper.sh` handles this automatically via a temporary venv — no user action required.

**Required tools:** `terraform fmt`, `terraform validate`  
**Optional but recommended:** `tflint`, `checkov`

## Advanced Features

Terraform 1.10+ introduces ephemeral values for secure secrets management. Terraform 1.14+ adds Actions for imperative operations and List Resources for querying infrastructure.

Read `references/advanced_features.md` when:
- Terraform version >= 1.10 is detected
- Configuration uses `ephemeral` blocks
- Configuration uses `action` blocks
- Configuration uses `.tfquery.hcl` files

## Integration with Other Skills

- **k8s-yaml-validator** — For Terraform Kubernetes provider validation
- **helm-validator** — When Terraform manages Helm releases
- **k8s-debug** — For debugging infrastructure provisioned by Terraform

Install with Tessl CLI

npx tessl i pantheon-ai/terraform-validator
Workspace
pantheon-ai
Visibility
Public
Created
Last updated