私は Terraform を学習中です。「計画」段階で変数の値を出力したいのですが、その方法を見つけました。どうやら私は何か間違っているようです...
variables.tf 内:....
variable "VMCount" {
description = "How many VMs do you want to start with (number)? default=1 max=5"
type = number
}
main.tf内
output "VMCount" {
value = "${var.VMCount > 2 && var.VMCount < 6 ? var.VMCount : 2}"
}
その後、terraform plan を実行すると、条件は正常に機能しているようです (適切な数の VM が作成されます)
しかし、変数の出力は行われません。なぜでしょうか?
$ terraform output
VMC = 56
VMC は以前の試みから来ている可能性があります (私はいくつかのことを試しました)。
ユーザーエントリ(変数)の値を印刷するにはどうすればいいですか?
ありがとう。
ベストアンサー1
私はこれでテストしました:
variable "VMCount" {
description = "How many VMs do you want to start with (number)? default=1 max=5"
type = number
}
output "VMCount" {
value = "${var.VMCount > 2 && var.VMCount < 6 ? var.VMCount : 2}"
}
そしてそれはうまく機能します。
Terraform will perform the following actions:
Plan: 0 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ VMCount = 4
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
VMCount = 4
PS C:\d\m\terraform\output-and-variable> terraform output
VMCount = 4
PS C:\d\m\terraform\output-and-variable> terraform apply
var.VMCount
How many VMs do you want to start with (number)? default=1 max=5
Enter a value: 8
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
Terraform will perform the following actions:
Plan: 0 to add, 0 to change, 0 to destroy.
Changes to Outputs:
~ VMCount = 4 -> 2
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
VMCount = 2
PS C:\d\m\terraform\output-and-variable> terraform output
VMCount = 2
PS C:\d\m\terraform\output-and-variable>
状態にどのような出力があるか確認できますか? VMC ですか、それとも VMCount ですか?