terraform.tfvars.jsonに変数値を記述する
ルール
Write variable values in terraform.tfvars.json. Environment-specific values in root modules, common values for all environments in repository root. However, it should be placed at the highest appropriate level in a monorepo.
(terraform.tfvars.jsonに変数値を記述する。環境固有の値はルートモジュールに、全環境共通の値はリポジトリルートに配置する。ただしモノレポの場合はふさわしいディレクトリのうち最上位でかまわない。)
解説
変数値はterraform.tfvarsその他ではなくterraform.tfvars.jsonに書きます。これはsopsを用いた暗号化の都合もあります。 なおリポジトリルートに配置するのはTerraform専用のリポジトリを使っている場合の話で、モノレポでさまざまなものが詰まっている場合はふさわしい場所のうち一番上位に配置します。たとえば<repository_root>/infrastructure/ です。
サンプルコード
// ./terraform.tfvars.json (リポジトリルート - 全環境共通)
{
"project": "practitioner",
"region": "ap-northeast-1"
}
// ./production/terraform.tfvars.json (環境固有)
{
"environment": "production",
"instance_type": "t3.medium",
"instance_count": 3
}
// ./development/terraform.tfvars.json (環境固有)
{
"environment": "development",
"instance_type": "t3.micro",
"instance_count": 1
}
参考リンク
備考
The reason for using the less readable json format is for ease of use with sops
Show Text to Shareterraform.tfvars.jsonに変数値を記述する https://www.tricrow.com/infrastructure/development-guidline/repository_structure.standard.tfvars.html

