【发布时间】:2021-11-28 15:27:45
【问题描述】:
我有用于配置 GCP 虚拟机的 terraform,它可以配置两个操作系统(windows 和 Unix)。
我有变量 os_distro=windows。
仅当 os_distro 是 windows 时,我才需要 windows-startup-script-ps1 = "${file("disk.ps1")}" 在元数据中。
meta_data_default = {
google-monitoring-enable = 1
google-logging-enable = 1
windows-startup-script-ps1 = var.os_distro == "windows" ? "${file("disk.ps1")}" : ""
}
上述块在 os_distro==windows 时有效,但在 os_distro==unix
时不需要windows-startup-script-ps1
请指导我。谢谢
【问题讨论】:
-
尝试用
null替换""空字符串。 -
谢谢马克。有用。但我的要求是如果它是 UNIX,我不想要 windows-startup-script-ps1 变量,因为这个变量仅适用于在启动时运行 powershell 的 Windows。有什么想法吗?
-
是否将其设置为
null不会删除它? -
这并不意味着除了windows之外有
null。意思是,这个变量应该只为windows定义,如果是其他,不需要定义变量。 -
查看 Terraform 文档对
nullhere 的评价。它被认为是没有设置。这意味着该值未定义。
标签: google-cloud-platform terraform terraform-provider-gcp