Back to Oh My Openagent

Terraform — LSP setup

packages/shared-skills/skills/lsp-setup/references/terraform/README.md

4.9.22.2 KB
Original Source

Terraform — LSP setup

An alias id terraform-ls exists with the identical command; either id works.

Install

  • macOS: brew install hashicorp/tap/terraform-ls
  • Linux: download a release from https://github.com/hashicorp/terraform-ls/releases and place terraform-ls on PATH (or apt/dnf via the HashiCorp repo)
  • Windows: choco install terraform-ls (or download a release zip)

terraform-ls requires the terraform binary itself to be installed and on PATH.

Confirm both resolve:

bash
command -v terraform-ls
command -v terraform

Configure

Builtin — usually NO config needed (auto-resolved by extension). Configure only to set priority, init options, override extensions, or disable. Same JSON shape in .codex/lsp-client.json (Codex) AND .opencode/lsp.json (OpenCode/omo):

json
{ "lsp": { "terraform": { "priority": 100 } } }

For builtin ids in a PROJECT config, command is supplied automatically — only set priority/initialization/extensions/disabled/env. A fully custom (non-builtin) server with its own command must go in the USER config (~/.codex/lsp-client.json).

Initialization options (only if commonly needed)

None commonly required. Provider/module completion comes from schemas generated by terraform init. Run it in each module root before expecting full completion:

bash
terraform init

To force schema indexing, you can set experimental features via initialization:

json
{ "lsp": { "terraform": { "initialization": { "experimentalFeatures": { "validateOnSave": true } } } } }

Alternatives

  • tflint standalone for opinionated linting (complements the LSP).
  • terraform fmt for formatting.

Troubleshooting

  • PATH: terraform-ls AND terraform both on PATH; reopen shell after install.
  • No provider completion: run terraform init so the .terraform/ schema cache exists.
  • .tfvars not analyzed: open the containing module so the server has root context.

Verify

bash
bun ../../scripts/verify-lsp.ts path/to/file.tf