Skip to content

Latest commit

 

History

History
125 lines (100 loc) · 3.84 KB

USAGE.md

File metadata and controls

125 lines (100 loc) · 3.84 KB

Usage of Terraform Language Server

This guide assumes you have installed the server by following instructions in the README.md if that is applicable to your client (i.e. if the client doesn't download the server itself).

Instructions for popular IDEs are below and pull requests for updates or addition of more IDEs are welcomed.

See also settings to understand how you may configure the settings.

Emacs

  • Install lsp-mode
  • Add the following to your .emacs:
(lsp-register-client
 (make-lsp-client :new-connection (lsp-stdio-connection '("/path/to/terraform-ls/terraform-ls" "serve"))
                  :major-modes '(terraform-mode)
                  :server-id 'terraform-ls))

(add-hook 'terraform-mode-hook #'lsp)

The last line can instead be (add-hook 'terraform-mode-hook #'lsp-deferred) if you prefer the server to lazy load.

IntelliJ IDE

  • Install LSP Support plugin
  • Open Settings
  • Go to Languages & Frameworks → Language Server Protocol → Server Definitions
    • Pick Executable
    • set Extension to tf
    • set Path to terraform-ls
    • set Args to serve
  • Confirm by clicking Apply

Please note that the Terraform plugin provides overlapping functionality (and more features at the time of writing). As a result having both enabled at the same time may result in suboptimal UX, such as duplicate completion candidates.

Sublime Text 2

  • Install the LSP package
  • Add the following snippet to your User LSP.sublime-settings (editable via Preferences → Package Settings → LSP → Settings or via the command pallete → Preferences: LSP Settings)
{
	"clients": {
		"terraform": {
			"command": ["terraform-ls", "serve"],
			"enabled": true,
			"languageId": "terraform",
			"scopes": ["source.terraform"],
			"syntaxes": ["Packages/Terraform/Terraform.sublime-syntax"]
		}
	}
}

Vim / NeoVim

coc.nvim

  • Install the coc.nvim plugin
  • Add the following snippet to the coc-setting.json file (editable via :CocConfig in NeoVim)
{
	"languageserver": {
		"terraform": {
			"command": "terraform-ls",
			"args": ["serve"],
			"filetypes": [
				"terraform",
				"tf"
			],
			"initializationOptions": {},
			"settings": {}
		}
	}
}

Make sure to read through the example vim configuration of the plugin, especially key remapping, which is required for completion to work correctly:

" Use <c-space> to trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()

vim-lsp

if executable('terraform-ls')
    au User lsp_setup call lsp#register_server({
        \ 'name': 'terraform-ls',
        \ 'cmd': {server_info->['terraform-ls', 'serve']},
        \ 'whitelist': ['terraform'],
        \ })
endif

VS Code

  • Install Terraform VS Code Extension >=2.0.0
  • Latest version of the language server should be installed automatically on VS Code launch
  • In case you are upgrading from v1 you may need to reset the settings to reflect v2 default, as shown below
"terraform.languageServer": {
    "args": [
        "serve",
    ],
},