Score:0

Terraform: How to Detect and Branch on Operating System?

us flag

Given this block of pseudo code from Terraform:

resource "null_resource" {
    provisioner "local-exec" {
        command = "echo hello"
        interpreter = local.os == "Windows" ? ["PowerShell", "-Command"] : ["bash"]
}

How would I get this to run in Powershell on Windows and bash on Linux?

Score:0
ph flag

local-exec usage inherently draws in details of the platform where you are running Terraform, which is one of the reasons why it should be treated as a last resort.

Terraform does not include any built-in way for a module to detect the host operating system. A custom Terraform provider could potentially offer a data source which returns that information, although if one were writing a Terraform provider anyway it may be more appropriate to write one to do whatever operation this provisioner would've been running directly, and thus avoid the need for the Terraform configuration to branch based on operating system.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.