微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何打印 terraform 变量值?

如何解决如何打印 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 计划并且条件似乎工作正常(它创建了正确数量的虚拟机)

但是变量输出没有来。为什么?

$ 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?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。