Skip to content

Instantly share code, notes, and snippets.

@aaronsteers
Last active April 23, 2020 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronsteers/4b7a964d36cadd1dc092800106c0f0b1 to your computer and use it in GitHub Desktop.
Save aaronsteers/4b7a964d36cadd1dc092800106c0f0b1 to your computer and use it in GitHub Desktop.
Platform-agnostic shell commands in Terraform
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