今天不可能。这是跨平台示例代码,您可以在任何环境中使用(托管在我的gist)。
首先一个 sn-p 来检测操作系统:
locals {
# Directories start with "C:..." on Windows; All other OSs use "/" for root.
is_windows = substr(pathexpand("~"), 0, 1) == "/" ? false : true
}
然后根据使用的操作系统选择解释器和命令:
resource "null_resource" "cli_command" {
provisioner "local-exec" {
# Ensure windows always uses PowerShell, linux/mac use their default shell.
interpreter = local.is_windows ? ["PowerShell", "-Command"] : []
# TODO: Replace the below with the Windows and Linux command variants
command = local.is_windows ? "sleep 60" : "sleep 60"
}
triggers = {
# TODO: Replace this psuedocode with one or more triggers that indicate (when changed)
# that the command should be re-executed.
"test_a" = resource.my_resource.sample
}
}
最后,一个没有额外 cmets 和触发器的简化视图:
resource "null_resource" "cli_command" {
provisioner "local-exec" {
interpreter = local.is_windows ? ["PowerShell", "-Command"] : []
command = "sleep 60"
}
}