mac版も書きました。
使い方はこちらの記事の方が参考になるかと思います。
tfswitchをmacにインストールする
tfswitchとは
https://warrensbox.github.io/terraform-switcher/
terraformのバージョンを簡単に切り替えられるツール。
最新へのバージョンアップもtfswitchコマンド叩いて選ぶだけ!便利!!
インストール手順
環境
$ cat /etc/system-release
Amazon Linux 2
手順
公式にある手順を実行。
$ sudo su -
# curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 9159 100 9159 0 0 9159 0 0:00:01 --:--:-- 0:00:01 88922
warrensbox/terraform-switcher info checking GitHub for latest tag
warrensbox/terraform-switcher info found version: 0.7.737 for 0.7.737/linux/amd64
warrensbox/terraform-switcher info installed /usr/local/bin/tfswitch
使い方
コマンド叩いて、使いたいバージョン選ぶだけ。
$ terraform --version
Terraform v0.12.18
[gitlab-runner@prod-gitlab-runner terraform]$ tfswitch
Use the arrow keys to navigate: ↓ ↑ → ←
? Select Terraform version:
▸ 0.12.19 ←選ぶ
0.12.18
0.12.17
0.12.16
↓ 0.12.15
✔ 0.12.19
Switched terraform to version "0.12.19"
$ terraform --version
Terraform v0.12.19
トラブルシューティング
インストール直後にコマンド実行すると権限のエラーが出ました。
$ tfswitch
2020/01/09 04:13:50 Creating directory for terraform: /home/ec2-user/.terraform.versions/
✔ 0.12.19
Downloading https://releases.hashicorp.com/terraform/0.12.19/terraform_0.12.19_linux_amd64.zip to terraform_0.12.19_linux_amd64.zip
Downloading ...
16530635 bytes downloaded.
2020/01/09 04:13:52
Unable to create new symlink.
Maybe symlink already exist. Try removing existing symlink manually.
Try running "unlink /usr/local/bin/terraform" to remove existing symlink.
If error persist, you may not have the permission to create a symlink at /usr/local/bin/terraform.
Error: symlink /home/ec2-user/.terraform.versions/terraform_0.12.19 /usr/local/bin/terraform: permission denied
セキュリティ的に問題ありそうですが、下記コマンドで動くようになりました。
$ sudo chmod 777 /usr/local/bin