Skip to content

Feature Request: HCL / Terraform (.tf) language support #83

@sachajw

Description

@sachajw

Summary

CodeGraph currently has no support for HCL/Terraform files (.tf, .tfvars, .hcl). Terraform is one of the most widely-used IaC tools, and many repos (especially infrastructure repos) consist entirely of .tf files. Currently these files are silently skipped during indexing with "No files found to index".

What's needed

A pre-compiled tree-sitter-hcl.wasm already exists in the npm ecosystem:

Adding support would follow the exact same pattern as existing languages — three changes:

  1. tree-sitter-wasms — vendor or reference the tree-sitter-hcl.wasm file
  2. grammars.js — add .tf/.tfvars/.hcl to EXTENSION_MAP, add hcl to WASM_GRAMMAR_FILES
  3. languages/hcl.js — create an HCL extractor (resource blocks, module blocks, data blocks, locals, variables, outputs, provider blocks, etc.) and register in languages/index.js

Key HCL/Terraform node types

The grammar exposes these block types that are relevant for code intelligence:

  • block — generic HCL block (with labels for resource/module/data names)
  • module_block — Terraform module references
  • resource_declaration / data_declaration — resource and data source references
  • variable_declaration / output_declaration / locals_declaration
  • provider_declaration / terraform_declaration
  • function_call — Terraform built-in functions

Example

resource "azurerm_resource_group" "example" {
  name     = "example-rg"
  location = "uksouth"
}

module "vnet" {
  source = "../modules/vnet"

  resource_group_name = azurerm_resource_group.example.name
}

data "azurerm_client_config" "current" {}

This would be extremely valuable for anyone using Claude Code with Terraform infrastructure repos. Happy to contribute a PR if you're open to it!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions