WSL の Ubuntu で Terraform を使う

Windows 10 の WSL 上の Ubuntu から Terraform を使えるようにしたくなったので、インストールしてみました。
インストールと言っても、バイナリファイルをダウンロードして、程よい場所に配置するだけの簡単操作です。

環境

Terraform のインストール

WSL 上の Ubuntu で以下のような感じでコマンドを実行します。

$ sudo apt-get update 
$ sudo apt-get upgrade 
$ sudo apt-get install unzip
$ wget https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip
$ unzip terraform_0.12.24_linux_amd64.zip
$ sudo mv terraform /usr/local/bin
$ rm terraform_0.12.24_linux_amd64.zip

これでインストールは完了です。
ディフォルトで「/usr/local/bin」へのPATHは通っていると思いますが、通っていない場合はPATHが通っているディレクトリに配置するか、PATHを通しておきましょう。

$ terrafrom -v
Terraform v0.12.24

いい感じです。

$ terraform init
Initializing modules...
- wordpress-us-vm in instance

Initializing the backend...

Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "google" (hashicorp/google) 3.17.0...

The following providers do not have any version constraints in configuration,
so the latest version was installed.

To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.

* provider.google: version = "~> 3.17"

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

無事に初期化もできました。
使えそうですね。