terraformの雛形作成
1.terraformをダウンロードする
$ curl -O https://releases.hashicorp.com/terraform/0.11.1/terraform_0.11.1_linux_amd64.zip
$ sudo unzip terraform_0.11.1_linux_amd64.zip -d /usr/bin/
$ terraform --version
2. git clone
$ git clone https://github.com/shodaisuzuki/terraform_stationery.git
構成について
$ tree
├── README.md
├── bin
│ ├── apply
│ ├── plan
│ └── terraform.exec.sh
├── environments
│ ├── production
│ │ ├── config
│ │ │ └── production.conf
│ │ ├── tfvars
│ │ │ ├── credential.tfvars
│ │ │ └── production.tfvars
│ │ └── user_data
│ │ └── user_data.sh
│ └── staging
│ ├── config
│ │ └── staging.conf
│ ├── tfvars
│ │ ├── credential.tfvars
│ │ └── staging.tfvars
│ └── user_data
│ └── user_data.sh
├── lib
│ ├── add_env
│ ├── remove_env
│ └── template
│ ├── config
│ │ └── template.conf
│ ├── tfvars
│ │ ├── credential.tfvars
│ │ └── template.tfvars
│ └── user_data
│ └── user_data.sh
├── tf
│ ├── auto_scaling.tf
│ ├── load_balancer.tf
│ ├── production
│ ├── staging
│ └── variables.tf
└── tfvars
└── common.tfvars
bin
実行ファイル
./terraform_stationery/bin/plan | apply env
例えば、production環境にplanする場合
$ ./terraform_stationery/bin/plan production
environments
環境ごとの設定値を記述
lib
$ lib/add_env XXX #環境追加
$ lib/remove/env XXX #環境削除
tf
AWS構成を定義する
ファイル名はサービス単位で作成
tf直下の.tfは共通のリソースを記述
variable.tfではtfファイルで使用する変数の定義を行う(実際の値はtfvarsから読み取る)
環境名の下には環境別のリソースを記述する
tfvars
tfファイルで使用する変数の値を書く
変数の定義はtf/bariable.tfで行う
共通の設定値をここに書き、環境別の設定値はenvironmentsの方に書く
参考
リファレンス
構築
http://made.livesense.co.jp/entry/2016/07/12/083000
https://tech.recruit-mp.co.jp/infrastructure/post-10665/
https://qiita.com/zembutsu/items/93e546df765f8b2c4f32
https://qiita.com/ringo/items/3af1735cd833fb80da75
壊れた時の復旧参考
https://qiita.com/minamijoyo/items/e0f69bfa853bef60977e#%E3%83%80%E3%83%9F%E3%83%BC%E3%81%AEtf%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E4%BD%9C%E3%82%8B
https://blog.stormcat.io/post/entry/2015/06/01/210500/