使用tfenv工具进行Terraform版本管理

1.安装tfenv

从GitHub上克隆过来。

git clone https://github.com/tfutils/tfenv.git ~/.tfenv

在.bash_profile中添加并应用环境变量PATH。

echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile

2. 安装 Terraform

以下是两种方法的描述:
1. 从Hashicorp下载ZIP的方式
从Hashicorp下载ZIP文件后解压缩,并将其移动到/usr/local/bin/目录下。

sudo curl https://releases.hashicorp.com/terraform/1.2.0/terraform_1.2.0_linux_amd64.zip -o terra.zip
unzip terra.zip -d /usr/local/bin/

确认terraform命令是否正常运行。

terraform --version
Terraform v1.2.0
on linux_amd64

在yum库中添加hashicorp.repo,并使用yum进行安装。
使用yum-config-manager命令方便地管理yum库。
前提是要安装yum-utils。

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform
bannerAds