Skip to content

Terraform LSP#


For more information about the LSP server, check terraform-ls.


For more instructions on how to install manually, check here.

Debugger: Not available#

author: psibi template: comment.html root_file: docs/manual-language-docs/

Server note#

Currently the mode supports two language servers. This FAQ entry shows how to choose a specific one. If you would want to go with the official Hashicorp's language server, set this:

(setq lsp-disabled-clients '(tfls))




Runs terraform validate on project root. All the violations are published back in the buffer.


Runs terraform init using terraform available from $PATH. You have to make sure that that proper credentials are there.

Note that this is a synchronous action and will timeout after a certain amount of time.

Code Lens#

This is an experimental feature which can be enabled via the option lsp-terraform-ls-enable-show-reference:

(setq lsp-terraform-ls-enable-show-reference t)

This gif demonstrates how this feature is used:

Semantic token support#

Make sure to enable these two variables to ensure that you have semantic token support for terraform mode:

(setq lsp-semantic-tokens-enable t)
(setq lsp-semantic-tokens-honor-refresh-requests t)

This is how the code looks without semantic tokens support:

And with semantic token support you get more contextual information via different faces:

Treeview controls#

For this feature to work, make sure that you have lsp-treemacs installed.

Providers widget#

This widget can be invoked by lsp-terraform-ls-providers.

Module calls widget#

This widget can be invoked by lsp-terraform-ls-module-calls.

If the modules data is empty, you might need to do terraform init for the project.

The widget has a minor mode named lsp-terraform-modules-mode. Following keybinding are available within the mode:

  • g: Refresh modules view

Available configurations#


Type: boolean

Default: nil

Enable reference counts.

Display reference counts above top level blocks and attributes. This is an experimental feature provided by the language server.


Type: list

Default: nil

The optional module calls tree position params. Defaults to side following treemacs default.


Type: list

Default: nil

The optional providers tree position params. Defaults to side following treemacs default.


Type: (choice (file :tag File) (repeat string))

Default: terraform-ls

Path to the terraform-ls binary.

Last update: June 25, 2022