Created
February 17, 2021 19:48
-
-
Save elmundio87/66363be4f4ef0e82b5132d0857b96006 to your computer and use it in GitHub Desktop.
OS-specific commands in Terraform local-exec
This file contains hidden or 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 { | |
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