convez.ai
LSP ServerDevOps & InfraestruturaIntermediário
zircote

Terraform LSP para Claude Code

zircote/terraform-lsp

IDE-like features e automação de qualidade para código Terraform

Ver no GitHub
BomPluginScore · de 0 a 100

Plugin de suporte completo para desenvolvimento Terraform em Claude Code, integrando terraform-ls com 17 hooks automatizados para validação, linting e segurança. Inclui integração com tflint, trivy, checkov e outras ferramentas do ecossistema Terraform, além de suporte a Terragrunt.

Instalação

$npx convez-ai zircote/terraform-lsp

1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.

Métricas

Estrelas
2
Forks
0
Acompanhando
0
Saúde
100%
Último commit
há 2 semanas
Versão
v0.1.3
Issues abertas
1
Contribuidores
2

Casos de uso

  • Escrever e validar configurações Terraform com IntelliSense em tempo real
  • Executar verificações de segurança (trivy, checkov) automaticamente ao editar
  • Implementar GitOps com hooks de format, validate e linting automáticos
  • Gerenciar múltiplas stacks Terraform/Terragrunt com diagnostics contínuos

Veredito

Ferramenta sólida e bem arquitetada para quem trabalha com Terraform em Claude Code. A integração de LSP com hooks automatizados reduz fricção significativamente, embora exija instalação de dependências externas (terraform-ls, tflint, trivy, checkov) para funcionalidade completa.

README

A tradução para o português deste README ainda está na fila.

terraform-lsp

Version License Claude Plugin Marketplace Terraform CI

A Claude Code plugin providing comprehensive Terraform development support through:

  • terraform-ls LSP integration for IDE-like features
  • 17 automated hooks for code quality, security, and validation
  • Terraform tool ecosystem integration (tflint, tfsec, checkov, etc.)

Quick Setup

# Run the setup command (after installing the plugin)
/setup

Or manually:

# macOS (Homebrew)
brew tap hashicorp/tap
brew install hashicorp/tap/terraform hashicorp/tap/terraform-ls \
             tflint tfsec checkov terraform-docs infracost terragrunt

Features

LSP Integration

The plugin configures terraform-ls for Claude Code via .lsp.json:

{
    "terraform": {
        "command": "terraform-ls",
        "args": ["serve"],
        "extensionToLanguage": {
            ".tf": "terraform",
            ".tfvars": "terraform-vars"
        },
        "transport": "stdio"
    }
}

Capabilities:

  • Go to definition / references
  • Hover documentation
  • Code completion for resources, data sources, variables
  • Module navigation and IntelliSense
  • Real-time diagnostics

Automated Hooks

All hooks run afterWrite and are configured in hooks/hooks.json.

Core Terraform Hooks

HookTriggerDescription
terraform-fmt-on-edit**/*.tfAuto-format with terraform fmt
terraform-validate-on-edit**/*.tfValidate configuration syntax
terraform-init-check**/*.tfWarn if terraform init is required
terraform-plan-hint**/main.tfSuggest running terraform plan

Linting & Quality

HookTriggerTool RequiredDescription
tflint-on-edit**/*.tftflintBest practices and provider-specific linting
terraform-todo-fixme**/*.tf-Surface TODO/FIXME/XXX/HACK comments

Security Scanning

HookTriggerTool RequiredDescription
trivy-on-edit**/*.tftrivySecurity vulnerability scanning (replaces tfsec)
checkov-on-edit**/*.tfcheckovCompliance and policy scanning
terraform-sensitive-check**/*.tf-Detect hardcoded secrets

Variable Files

HookTriggerDescription
tfvars-fmt-on-edit**/*.tfvarsAuto-format variable files
tfvars-sensitive-check**/*.tfvarsWarn about sensitive values

Terragrunt Support

HookTriggerTool RequiredDescription
terragrunt-fmt-on-edit**/terragrunt.hclterragruntFormat Terragrunt files
terragrunt-validate**/terragrunt.hclterragruntValidate Terragrunt config

Contextual Hints

HookTriggerDescription
terraform-docs-hint**/variables.tfSuggest documentation update
terraform-cost-hint**/main.tfSuggest cost estimation with infracost
terraform-lock-outdated**/.terraform.lock.hclSuggest provider upgrade

Other

HookTriggerDescription
markdown-lint-on-edit**/*.mdLint markdown files

Required Tools

Core (HashiCorp)

ToolInstallationPurpose
terraformbrew install hashicorp/tap/terraformInfrastructure provisioning
terraform-lsbrew install hashicorp/tap/terraform-lsLSP server

Recommended Linting & Security

ToolInstallationPurpose
tflintbrew install tflintTerraform linter
trivybrew install trivySecurity scanner (replaces tfsec)
checkovpip install checkovCompliance scanner

Optional Utilities

ToolInstallationPurpose
terraform-docsbrew install terraform-docsDocumentation generator
infracostbrew install infracostCost estimation
terragruntbrew install terragruntMulti-environment management

Commands

/setup

Interactive setup wizard for configuring the complete Terraform development environment.

What it does:

  1. Verifies Terraform installation - Checks terraform CLI is available
  2. Installs terraform-ls - LSP server for IDE features
  3. Installs linting tools - TFLint with provider plugins
  4. Installs security scanners - tfsec and checkov
  5. Validates LSP config - Confirms .lsp.json is correct
  6. Initializes TFLint config - Sets up .tflint.hcl (if needed)
  7. Verifies hooks - Confirms hooks are properly loaded

Usage:

/setup

Quick install command (macOS):

brew tap hashicorp/tap && \
brew install hashicorp/tap/terraform hashicorp/tap/terraform-ls \
             tflint tfsec checkov terraform-docs infracost terragrunt

Configuration

.tflint.hcl

Initialize TFLint for your cloud provider:

# Create config
cat > .tflint.hcl << 'EOF'
plugin "terraform" {
  enabled = true
  preset  = "recommended"
}

plugin "aws" {
  enabled = true
  version = "0.31.0"
  source  = "github.com/terraform-linters/tflint-ruleset-aws"
}
EOF

# Install plugins
tflint --init

Customizing Hooks

Edit hooks/hooks.json to:

  • Disable hooks by removing entries
  • Adjust output limits (head -N)
  • Modify matchers for different file patterns
  • Add project-specific hooks

Example - disable a hook:

{
    "name": "checkov-on-edit",
    "enabled": false,
    ...
}

Project Structure

terraform-lsp/
├── .claude-plugin/
│   └── plugin.json           # Plugin metadata
├── .lsp.json                  # terraform-ls configuration
├── commands/
│   └── setup.md              # /setup command
├── hooks/
│   └── hooks.json            # 17 automated hooks
├── CLAUDE.md                  # Project instructions
└── README.md                  # This file

Troubleshooting

terraform-ls not starting

  1. Ensure .tf files exist in project root
  2. Run terraform init to initialize providers
  3. Verify installation: terraform-ls --version
  4. Check LSP config: cat .lsp.json

terraform validate fails

Initialize the working directory first:

terraform init

tflint errors

Initialize and update plugins:

tflint --init
tflint --init --upgrade

trivy/checkov not detecting issues

  1. Verify scanning correct directory
  2. Update tools: brew upgrade trivy checkov
  3. Check for exclusion patterns
  4. For trivy: ensure trivy config (not trivy fs) for IaC scanning

Hooks not triggering

  1. Verify hooks are loaded: cat hooks/hooks.json
  2. Check file patterns match your structure
  3. Ensure required tools are installed (command -v tflint)

Too much output

Reduce head -N values in hooks.json for less verbose output.

License

MIT

Ver o original no GitHub

Bom para

Relacionados