问题描述
我正在学习地形。我想在“计划”阶段打印变量的值。所以我找到了怎么做。似乎我在这里做错了什么......
在 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 计划并且条件似乎工作正常(它创建了正确数量的虚拟机)
但是变量输出没有来。为什么?
$ terraform output
VMC = 56
VMC 可能来自之前的一些尝试(我尝试了几种方法)。
如何打印用户输入的值(变量)?
谢谢。
解决方法
我用这个测试过:
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 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 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?