安装go环境
根据go.mod文件查看go的版本要求
下载go安装包https://golang.google.cn/dl/
1 | wget https://golang.google.cn/dl/go1.17.linux-amd64.tar.gz |
修改环境变量vi /etc/profile
1 | export GOROOT=/opt/go |
使环境变量生效source /etc/profile
编译terraformer
Run git clone && cd terraformer/
Run git clone && cd terraformer/
Run go mod download (下载模块到本地缓存,缓存路径是 $GOPATH/pkg/mod/cache)
Run go build -v for all providers OR build with one provider: go run build/main.go {google,aws,azure,kubernetes and etc}
.Run terraform init against a versions.tf file to install the plugins required for your platform. For example, if you need plugins for the google provider, versions.tf should contain:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16terraform {
required_providers {
google = {
source = "hashicorp/google"
}
}
required_version = ">= 0.13"
}
# if need aws
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}Or alternatively Copy your Terraform provider’s plugin(s) to
folder ~/.terraform.d/plugins/{darwin,linux}_amd64/, as appropriate.
cp terraform-provider-aws_v3.57.0_x5 /root/.terraform.d/plugins/linux_amd64/
terraform 安装
1 | $ wget https://releases.hashicorp.com/terraform/1.0.5/terraform_1.0.5_linux_amd64.zip |
默认会下载aws插件到当前隐藏目录 ./terraform/.terraform/providers/registry.terraform.io/hashicorp/aws/3.57.0/linux_amd64/terraformprovider-aws_v3.57.0_x5
国内下载不了插件,可以去github下载release进行go编译;或者翻墙下载 https://registry.terraform.io/providers/hashicorp/aws/latest
资源tf抓取测试
1 | # ./terraformer-aws import aws --resources s3 |
文件会保存在当前的generated目录下
第二种安装方式
除了通过源码进行安装,还有一种比较简单的安装方式是下载对应的terraformer二进制安装包,地址如下:
https://github.com/GoogleCloudPlatform/terraformer/releases
找到对应云厂商的terraformer二进制包即可。这里选择AWS。terraformer-aws-linux-amd64
如果是windows,则选择对应的terraformer-aws-windows-amd64.exe
1 | [root@localhost demoterraform]# wget https://github.com/GoogleCloudPlatform/terraformer/releases/download/0.8.19/terraformer-aws-linux-amd64 |
输入terraform-aws
查看命令有无生效.
1 | [root@localhost demoterraform]# terraform-aws |