【参考】
■GitHub
https://github.com/GoogleCloudPlatform/terraformer
■先人の知恵
Terraformerを使用して既存のAWS環境をエクスポートする | zoo200's MemoMemo
https://dev.classmethod.jp/articles/terraformer-aws-check/
https://qiita.com/shogomuranushi/items/98cf2c9800187f51e982
https://qiita.com/kukita/items/d7e0fe9c0d84cdcdfa31
https://qiita.com/data_psyence/items/cd3acafb177ea7e5f755
【環境構築概要】事前作業
■Windows10+WSL2にterrafromを入れて動かす
以下の手順のを進めておく
https://zuntan02.hateblo.jp/entry/2021/05/06/144646
■AWS Cliのインストール
【参照】https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/install-cliv2-linux.html#cliv2-linux-install
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip awscliv2.zip sudo ./aws/install
※aws configureで該当のAWSIAMが設定されている前提で進めます
【メモ】【俺メモ】AWS CLIで複数のIAMを使い分ける - zuntan02のはてなブログ
terraformerインストール
# GitHub上のFrom Releases-Linux の記述(バイナリの取得と配置)を実行
# export PROVIDER={all,google,aws,kubernetes} export PROVIDER=aws curl -LO https://github.com/GoogleCloudPlatform/terraformer/releases/download/$(curl -s https://api.github.com/repos/GoogleCloudPlatform/terraformer/releases/latest | grep tag_name | cut -d '"' -f 4)/terraformer-${PROVIDER}-linux-amd64 chmod +x terraformer-${PROVIDER}-linux-amd64 sudo mv terraformer-${PROVIDER}-linux-amd64 /usr/local/bin/terraformer
# バージョン確認
terraformer --version
# version v0.8.16
■動作検証
# 初期設定 vi init.tf provider "aws" { region = "ap-northeast-1" } terraform init
VPCの情報をtfにして取り出してみます
terraformer import aws --regions=ap-northeast-1 --resources=vpc
→作業ディレクトリ/generated/aws/vpc
以下にtfファイルおよびtfstateファイルが出力された。
tfstateをみると
"version": 3, "terraform_version": "0.12.31",
となっていて、0.12の書式であることがわかる。そのまま使えそう。
いったんここまで。
※おまけ
ソースコンパイル版
上記リリース版取ってきて配置するほうが簡単なので、あえてやることもないけど念のため。
■goの最新版インストール(最新化)
今回のterraformerではgo1.15以上が必要というメッセージが出たため以下の手順で最新化した
# インストール済みパッケージを削除 sudo apt-get remove golang-go # goの最新版(1.17)を配置 cd ~/workdir wget https://dl.google.com/go/go1.17.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz vi ~/.bash_profile export PATH="$PATH:/usr/local/go/bin" source ~/.bash_profile go version # go version go1.17 linux/amd64
【terraformerインストール】
# インストール済みパッケージの更新 sudo apt-get update sudo apt-get upgrade # terraformerのインストール git clone https://github.com/GoogleCloudPlatform/terraformer.git && cd terraformer/ go mod download # go build -v だとめちゃくちゃ重いので、今回必要なaws用のterraformerのみビルドした go run build/main.go aws # 出来上がったバイナリ(terraformer-aws)の移動 # 置き場は /usr/local/bin/terraformer とする sudo mkdir /usr/local/bin/terraformer sudo mv terraformer-aws /usr/local/bin/terraformer/ # パスを追加 vi ~/.bash_profile export PATH="$PATH:/usr/local/bin/terraformer" source ~/.bash_profile # バージョン確認 terraformer-aws --version # version v0.8.16