1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

vimでterraform-lspを使いたい

Posted at

はじめに

vimに入門しました。terraformの勉強を始めたんですが、lspとやらが便利とのことなので試してみることにしました。

環境

OS macOS Catalina 10.15.5
管理ツール Homebrew
plugin管理 dein
terraform 0.12.5

注意

terraformのバージョンは、0.12.20より小さくしておいてください。
参考
hashicorp/terraform-ls
juliosueiras/terraform-lsp

下準備

terraform-lspを動かすためのLSPを用意しなければなりません。coc.nvimをインストールします。プラグイン管理はdeinを利用しているため、以下を追記しました。

call dein#add('neoclide/coc.nvim', {'merged':0, 'rev': 'release'})

coc.nvimを動かすためにはnodeが必要です。インストール済みでない場合は、homebrewでインストールしましょう。

$ brew install node

これで下準備は完了です。

インストール

terraform-lspを利用するためには、goが必要です。インストールしていない場合は、homebrewでインストールしましょう。

$ brew install go

juliosueiras/terraform-lspを利用します。またterraform-lspは~/.binにセットアップされるため、初回はパスを通す必要があります。

# terraform-lspのインストールとセットアップ
$ git clone https://github.com/juliosueiras/terraform-lsp
$ cd terraform-lsp
$ GO111MODULE=on go mod download
$ make
$ make copy

# パスを通す
echo 'export PATH=$PATH:~/.bin' >> ~/.bash_profile
source ~/.bash_profile

プラグインのインストールが完了したら、cocの設定をしていきましょう。vimで以下のコマンドを叩くと、~/.vim/coc-setting.jsonを編集することができます。

:CocConfig

terraform-lspのVim Supportより
Vim Support

~/.vim/coc-setting.json
{
	"languageserver": {
		"terraform": {
			"command": "terraform-lsp",
			"filetypes": [
				"terraform",
				"tf"
			],
			"initializationOptions": {},
			"settings": {}
		}
	}
}

使い方

juliosueiras/terraform-lspで利用方法の動画あるので確認してください。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?