当想要在M1 Mac上使用asdf和terraform0.1系列时的方法
※ 环境假设为Mac(Apple M1)。
井井有条
在需要使用不同工具的运行时版本时使用。这次我想要根据需要使用不同的 Terraform 版本进行安装。
Terraform版本为0.1系。
2022年7月時点,0.1版本已经过时。
现在,最新版本是1.2.x(通过经历了0.14、0.15、1.0.0等版本升级而来)。
0.1版本虽然老旧,但如果需要使用的话,可以通过asdf进行安装。例如,0.13.7版本。
❯ asdf install terraform 0.13.7
基于Arm架构的Mac电脑
❯ uname -m
arm64
然而,对于M1芯片的Arm架构M1 Mac来说,不存在适用于该环境的0.13.7二进制文件。
❯ asdf install terraform 0.13.7
Downloading terraform version 0.13.7 from https://releases.hashicorp.com/terraform/0.13.7/terraform_0.13.7_darwin_arm.zip
Error: terraform version 0.13.7 not found
从错误消息来看,缺少适用于当前环境的文件 terraform_0.13.7_darwin_arm.zip。下载这个文件并通过asdf的reshim命令进行安装,就可以暂时使用。
以下是步骤。这次我们希望仅使用asdf命令完成。
ARM平台的公式发布版本从1.0.2开始分发。
有 terraform_1.0.2_darwin_arm64.zip。因此,可以通过 asdf 进行安装。
由于没有以下所示的 1.0.1 文件,因此通过 asdf 进行安装会失败。
❯ asdf install terraform 1.0.1
Downloading terraform version 1.0.1 from https://releases.hashicorp.com/terraform/1.0.1/terraform_1.0.1_darwin_arm.zip
Error: terraform version 1.0.1 not found
❯ asdf install terraform 1.0.2
Downloading terraform version 1.0.2 from https://releases.hashicorp.com/terraform/1.0.2/terraform_1.0.2_darwin_arm64.zip
Skipping verifying signatures and checksums either because gpg is not installed or explicitly skipped with ASDF_HASHICORP_SKIP_VERIFY
Cleaning terraform previous binaries
Creating terraform bin directory
Extracting terraform archive
通过asdf安装terarform0.13.7的方法是什么?
如果你一定要使用0.15.x或0.13.x版本的话,可以采取以下对策。
❯ arch -arch x86_64 asdf install terraform 0.13.7
Downloading terraform version 0.13.7 from https://releases.hashicorp.com/terraform/0.13.7/terraform_0.13.7_darwin_amd64.zip
Skipping verifying signatures and checksums either because gpg is not installed or explicitly skipped with ASDF_HASHICORP_SKIP_VERIFY
Cleaning terraform previous binaries
Creating terraform bin directory
Extracting terraform archive
通过使用arch命令,可以更改指定文件名。
安装terraform_0.13.7_darwin_amd64.zip文件以及darwin_amd64后,即可进行安装,因为文件已经存在。
然而,由于这样的前提设定是针对Intel架构的,所以无法成功执行。
bash: Job 1, ‘terraform’ terminated by signal SIGSEGV (Address boundary error)
在进行作业过程中可能会出现强制终止的情况。
因此,在执行时也需要使用arch来指定体系结构。
架构-架构x86_64
❯ arch -arch x86_64 terraform -v
Terraform v0.13.7
通过这样,可以执行Intel架构指定的操作,从而使其正常运行。