Skip to content

Instantly share code, notes, and snippets.

@elmundio87
Created February 17, 2021 19:48
Show Gist options
  • Save elmundio87/66363be4f4ef0e82b5132d0857b96006 to your computer and use it in GitHub Desktop.
Save elmundio87/66363be4f4ef0e82b5132d0857b96006 to your computer and use it in GitHub Desktop.
OS-specific commands in Terraform local-exec
locals {
platform = substr(pathexpand("~"),0,1) == "/" ? "linux" : "windows"
command_map = {
windows = {
interpreter = "powershell",
command = "While( -not $(az account list-locations)){ Start-Sleep 5 }; echo Done!"
}
linux = {
interpreter = "bash",
command = "while ! az account list-locations){ Sleep 5 }; echo Done!"
}
}
}
# Wait for Azure CLI to complete without explicit dependency
resource "null_resource" "localexec" {
provisioner "local-exec" {
command= lookup(local.command_map, local.platform, null).command
interpreter = [lookup(local.command_map, local.platform, null).interpreter]
}
triggers = {
trigger = timestamp()
}
}
# Log into Azure via CLI
resource "null_resource" "localexec2" {
provisioner "local-exec" {
command = "az login -o none --only-show-errors"
}
triggers = {
trigger = timestamp()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment