1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Google Cloud ShellでTerraformerを使う

Last updated at Posted at 2020-10-15

使うもの

Google Cloud Shell

GCP上に用意してくれる、作業用シェル環境。
Terraformも既に入っているので便利。
https://cloud.google.com/shell/docs/using-cloud-shell?hl=ja

Terraformer

既存のGCPインフラ構成からTerraformのtfファイルやtfstateファイルを生成してくれるツール。
GUIで先に作ってみて、後からtfファイルが欲しい(インフラ構成をコード化したい)時に便利。
GCP以外にも色々対応してるらしい。
https://github.com/GoogleCloudPlatform/terraformer

使い方

ドキュメントに従ってTerraformerをインストール。
https://github.com/GoogleCloudPlatform/terraformer#installation

CloudShell
export PROVIDER=google
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

作業ディレクトリを作って、google providerのバージョンを指定。

CloudShell

mkdir work
cd work
vi main.tf
main.tf
provider "google" {
  version = "3.11.0" # 使っているバージョンに合わせる
}

Terraformerを実行。

CloudShell
#対象のリソースとプロジェクトは適宜指定する
terraformer import google --resources=monitoring --projects=sandbox-xxxxxxxx

#この辺に生成される
cat generated/google/sandbox-xxxxxxxx/monitoring/global/monitoring_notification_channel.tf 
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?