尝试在EC2上安装terraform
在EC2(AmazonLinux2、x86_64)上安装Terraform。
一种选择是:启动 EC2 实例。
使用以下内容启动实例。详细信息略。
– AmazonLinux2
– t2.micro
– 公共子网
– 附加了AdministratorAccess策略的角色
– 安全组
入站:仅允许SSH
出站:允许所有
SSH连接
使用SSH客户端连接到EC2实例。
本次使用Teraterm。
③ [无论何种形式] 更新 AWS CLI
由于本次实例是Amazon Linux 2,所以AWS CLI已经预先安装进去。
然而,由于版本可能过旧,所以如果是1.xx版本的话,最好升级到2.xx版本以确保安全。
执行 aws –version 命令,如果版本是1.xx,则按照以下步骤升级版本:
https://qiita.com/simis/items/46ffe04c346b9fdf7830
安装 Terraform
公式的安装手册在这里。https://learn.hashicorp.com/terraform/getting-started/install.html
按照所写的去做。流程如下所示。
・下载包装
・解压包装
・通过路径
顺便提一下,即使称之为“包装”,实际上里面只有一个名为terraform的二进制文件。因此,要安装它,只需将其二进制文件添加到PATH环境变量,或者将该二进制文件移动到已经在PATH中的目录即可。(当然,也可以使用ln -s命令创建软链接)。
这次尝试采用后者(将二进制文件移动到已经添加了路径的目录)。
■软件包下载
提供的版本在这里。
https://releases.hashicorp.com/terraform/
这次我们尝试使用0.12.28版本(截至2020年7月11日的最新版本)。
$ wget https://releases.hashicorp.com/terraform/0.12.28/terraform_0.12.28_linux_amd64.zip
--2020-07-11 08:52:09-- https://releases.hashicorp.com/terraform/0.12.28/terraform_0.12.28_linux_amd64.zip
Resolving releases.hashicorp.com (releases.hashicorp.com)... 151.101.109.183, 2a04:4e42:1a::439
Connecting to releases.hashicorp.com (releases.hashicorp.com)|151.101.109.183|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28425934 (27M) [application/zip]
Saving to: ‘terraform_0.12.28_linux_amd64.zip’
100%[=================================================================================================>] 28,425,934 74.3MB/s in 0.4s
2020-07-11 08:52:10 (74.3 MB/s) - ‘terraform_0.12.28_linux_amd64.zip’ saved [28425934/28425934]
$
■文件解压缩
$ unzip terraform_0.12.28_linux_amd64.zip
Archive: terraform_0.12.28_linux_amd64.zip
inflating: terraform
$
Terraform应该已经被解压缩成二进制文件了。
■无障碍通道
首先确认当前的路径。
$ echo $PATH
/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/ec2-user/.local/bin:/home/ec2-user/bin
$
不论把二进制文件移动到哪里都可以,但这次我决定首先将其移动到 /usr/local/bin。
$ sudo mv terraform /usr/local/bin
$
$
$ ls -l /usr/local/bin/terraform
-rwxr-xr-x 1 ec2-user ec2-user 69818039 Jun 25 13:11 /usr/local/bin/terraform
$
确认动作
确认二进制文件可执行。
尝试通过指定-help选项查看是否能显示帮助信息。
$ terraform -help
Usage: terraform [-version] [-help] <command> [args]
The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.
Common commands:
apply Builds or changes infrastructure
console Interactive console for Terraform interpolations
destroy Destroy Terraform-managed infrastructure
env Workspace management
fmt Rewrites config files to canonical format
get Download and install modules for the configuration
graph Create a visual graph of Terraform resources
import Import existing infrastructure into Terraform
init Initialize a Terraform working directory
login Obtain and save credentials for a remote host
logout Remove locally-stored credentials for a remote host
output Read an output from a state file
plan Generate and show an execution plan
providers Prints a tree of the providers used in the configuration
refresh Update local state file against real resources
show Inspect Terraform state or plan
taint Manually mark a resource for recreation
untaint Manually unmark a resource as tainted
validate Validates the Terraform files
version Prints the Terraform version
workspace Workspace management
All other commands:
0.12upgrade Rewrites pre-0.12 module source code for v0.12
debug Debug output management (experimental)
force-unlock Manually unlock the terraform state
push Obsolete command for Terraform Enterprise legacy (v1)
state Advanced state management
$
整理房间
请不要删除文件(下载文件)。
$ rm terraform_0.12.28_linux_amd64.zip
$