使用 tfenv 在 M1 处理器兼容的环境中安装 Terraform
动机
为了避免这个问题的错误,我想通过 tfenv 避免安装 amd64 版本的 Terraform。
当执行 tfenv install **** 时,会默认安装 amd64。
$ tfenv install 1.2.2
Installing Terraform v1.2.2
Downloading release tarball from https://releases.hashicorp.com/terraform/1.2.2/terraform_1.2.2_darwin_amd64.zip
######################################################################################################################################################################################################################################################### 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.2.2/terraform_1.2.2_SHA256SUMS
No keybase install found, skipping OpenPGP signature verification
Archive: tfenv_download.WOq4o7/terraform_1.2.2_darwin_amd64.zip
inflating: /opt/homebrew/Cellar/tfenv/2.2.2/versions/1.2.2/terraform
Installation of terraform v1.2.2 successful. To make this your default version, run 'tfenv use 1.2.2'
环境
M1款MacBook Air
解决方案
只需传递arm64就好。这在README.md中已经写了。
TFENV_ARCH=arm64
$ TFENV_ARCH=arm64 tfenv install 1.2.2
Installing Terraform v1.2.2
Downloading release tarball from https://releases.hashicorp.com/terraform/1.2.2/terraform_1.2.2_darwin_arm64.zip
######################################################################################################################################################################################################################################################### 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.2.2/terraform_1.2.2_SHA256SUMS
No keybase install found, skipping OpenPGP signature verification
Archive: tfenv_download.zmM3xS/terraform_1.2.2_darwin_arm64.zip
inflating: /opt/homebrew/Cellar/tfenv/2.2.2/versions/1.2.2/terraform
Installation of terraform v1.2.2 successful. To make this your default version, run 'tfenv use 1.2.2'
看起来你是想要去 Terraform 官方下载页面查看 URL,但只有 arm 平台是不行的。
TFENV_ARCH=arm tfenv install 1.2.2
Installing Terraform v1.2.2
Downloading release tarball from https://releases.hashicorp.com/terraform/1.2.2/terraform_1.2.2_darwin_arm.zip
#=#=- # #
#=O#- # #
-#O=- # # #
curl: (22) The requested URL returned error: 404
Tarball download failed
似乎最好在.zshrc和.bashrc中设置环境变量始终处于活动状态。
如果在amd64上执行了terraform init,则在arm64上重新安装后再次执行terraform init。