是否有方法可以覆盖local-exec
预配器中使用的默认Terraform解释器?
我知道您可以通过interpreter
参数设置解释器,但是我试图避免在每个单独的资源上都指定它。
我真正想做的是覆盖“明智的默认值...基于系统OS选择”,以使脚本跨平台。具体来说,我想通过环境或命令行变量更改默认值,以便可以将Windows上的Cygwin Bash用于最初为Linux制作的脚本。
是否存在这种能力?
今天不可能。这是跨平台的示例代码,您可以在任何环境中使用(托管在我的gist上)。
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
}
}