Ubuntu18.04LTS on WSL2 on Windows10でやった。
最近Terraform LayerにLSPサポートが入ったので満を持して。。。
保存時に自動フォーマットする
terraform-auto-format-on-saveを有効にする。
(defun dotspacemacs/layers ()
'(
(terraform :variables
terraform-auto-format-on-save t)
)
)
LSPを使う
LSPを経由して自動補完やlinterの機能を使う。
前置き:
Spacemacsが利用する lsp-modeにはクライアントとして lsp-terraformが含まれている。内部ではterraform-lspを使っている。
手順はこう。
- Goをインストール
- terraform-lspをインストール
- SpacemacsでLSPを使うように設定
Goをインストール
terraform-lspをビルドするためにはGo (golang)が必要とのこと。
it will need Go 1.14+
今回はUbuntuに手動インストール。
Go公式サイトから go1.14.4.linux-amd64.tar.gzをダウンロードした (terraform-lspが要求するバージョン以降を)
cd ~
wget https://dl.google.com/go/go1.14.4.linux-amd64.tar.gz
次はinstallation instructionsに従ってGoをインストールし、環境変数のパス設定と反映まで行う。
tar -C /usr/local -xzf go$VERSION.$OS-$ARCH.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.bash_profile
source ~/.bash_profile
go versionや go --helpが使えれば完。
terraform-lspをインストール
リリースをダウンロードする or リポジトリをcloneする の方法がある。
cloneするほうでやった。
git clone https://github.com/juliosueiras/terraform-lsp.git
もし ~/.bin/ディレクトリがなければ作っておく。
ビルド先のようなので、環境変数のパス設定と反映まで行う。
mkdir ~/.bin
echo 'export PATH=$PATH:$HOME/.bin' >> ~/.bash_profile
source ~/.bash_profile
公式に従ってビルド。cloneしたディレクトリ下 ( terraform-lsp/)で行う。
GO111MODULE=on go mod download
make
make copy
successすれば terraform-lspコマンドが使えるようになる。完
SpacemacsでLSPを使うように設定する
terraform-backendの値を 'lspにする。
(defun dotspacemacs/layers ()
'(
(terraform :variables
terraform-backend 'lsp)
)
)
