Last active
April 23, 2020 18:45
-
-
Save aaronsteers/4b7a964d36cadd1dc092800106c0f0b1 to your computer and use it in GitHub Desktop.
Platform-agnostic shell commands in Terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" { | |
# Keep as-is. This ensures 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 variants | |
command = local.is_windows ? "sleep 60" : "sleep 60" | |
} | |
triggers = { | |
# TODO: Replace this psuedocode with the trigger that indicates (when changed) | |
# that the command should be re-executed. | |
"test_a" = resource.my_resource.sample | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also here: https://stackoverflow.com/questions/52628749/set-terraform-default-interpreter-for-local-exec/61392460#61392460