terraform-lsp

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
| Hook | Trigger | Description |
|---|
terraform-fmt-on-edit | **/*.tf | Auto-format with terraform fmt |
terraform-validate-on-edit | **/*.tf | Validate configuration syntax |
terraform-init-check | **/*.tf | Warn if terraform init is required |
terraform-plan-hint | **/main.tf | Suggest running terraform plan |
Linting & Quality
| Hook | Trigger | Tool Required | Description |
|---|
tflint-on-edit | **/*.tf | tflint | Best practices and provider-specific linting |
terraform-todo-fixme | **/*.tf | - | Surface TODO/FIXME/XXX/HACK comments |
Security Scanning
| Hook | Trigger | Tool Required | Description |
|---|
trivy-on-edit | **/*.tf | trivy | Security vulnerability scanning (replaces tfsec) |
checkov-on-edit | **/*.tf | checkov | Compliance and policy scanning |
terraform-sensitive-check | **/*.tf | - | Detect hardcoded secrets |
Variable Files
| Hook | Trigger | Description |
|---|
tfvars-fmt-on-edit | **/*.tfvars | Auto-format variable files |
tfvars-sensitive-check | **/*.tfvars | Warn about sensitive values |
Terragrunt Support
| Hook | Trigger | Tool Required | Description |
|---|
terragrunt-fmt-on-edit | **/terragrunt.hcl | terragrunt | Format Terragrunt files |
terragrunt-validate | **/terragrunt.hcl | terragrunt | Validate Terragrunt config |
Contextual Hints
| Hook | Trigger | Description |
|---|
terraform-docs-hint | **/variables.tf | Suggest documentation update |
terraform-cost-hint | **/main.tf | Suggest cost estimation with infracost |
terraform-lock-outdated | **/.terraform.lock.hcl | Suggest provider upgrade |
Other
| Hook | Trigger | Description |
|---|
markdown-lint-on-edit | **/*.md | Lint markdown files |
Required Tools
Core (HashiCorp)
| Tool | Installation | Purpose |
|---|
terraform | brew install hashicorp/tap/terraform | Infrastructure provisioning |
terraform-ls | brew install hashicorp/tap/terraform-ls | LSP server |
Recommended Linting & Security
| Tool | Installation | Purpose |
|---|
tflint | brew install tflint | Terraform linter |
trivy | brew install trivy | Security scanner (replaces tfsec) |
checkov | pip install checkov | Compliance scanner |
Optional Utilities
| Tool | Installation | Purpose |
|---|
terraform-docs | brew install terraform-docs | Documentation generator |
infracost | brew install infracost | Cost estimation |
terragrunt | brew install terragrunt | Multi-environment management |
Commands
/setup
Interactive setup wizard for configuring the complete Terraform development environment.