Terraformをはじめよう
input variable(入力変数)
-
description 用途などかく
-
default デフォルト値がない場合、対話的に入力を求められる。
-
type string,number,bool,list,map etc.. 型定義
-
validation 最大値や最小値など、定義をカスタマイズできる。
-
sensitive ログ出力などの値を秘匿化する
-
記述例
variable "security_group_name" {
description = "The name of the security group"
type = string
default = "terraform-example-instance"
}
- 参照例 コマンドラインから
terrafrom plan -var "server_port=8080"
- 参照例 環境変数から
export TF_VAR_server_port=8080
- 参照例 コードから
var.server_port=8080
output variable(出力変数)
-
description 用途などかく
-
sensitive ログ出力などの値を秘匿化する
-
depends_on ??
-
記述例
output "public_ip" {
value = aws_instance.example.public_ip
description = "The public IP of the Instance"
}
ステートを管理する
terraform.tfstate(apply実行するとできる。)
ワークスペースによる分離
ファイルレイアウトによる分離
- トツプレベルフォルダの例
- stage
- prod
- mgmt(DevOpsツール環境、踏み台、CIサーバなど)
- global(全環境をまたぐリソースS3,IAM)
- セカンド、サードレベル
- vpc(ネットワーク)
- services(アプリケーション群)
-- frontend-app
-- backend-app
- data-storage(データストア用)
- 各個別フォルダ
- variables.tf(入力変数)
- output.tf(出力変数)
- main.tf(リソースとデータソース)