scottwinkler / terraform-provider-shell

Terraform provider for executing shell commands and saving output to state file
Mozilla Public License 2.0
279 stars 60 forks source link

Zd/provider config #51

Closed derhally closed 4 years ago

derhally commented 4 years ago

Implementation for PR for #49 .

Let's you set variables on the shell provider so they are always passed in on each script execution. Allows resources that are being deleted to get up-to-date env values if they need it.

Edit: The environment variables on the resource take priority over the provider environment variables.

Example:

resource "random_string" "random" {
  length = 5
}

provider "shell" {
    environment = {
        "TOKEN" = random_string.random.result
    }
}

resource "shell_script" "test" {
    lifecycle_commands {
    create = <<-EOF
        echo "$TOKEN" > create.txt
        echo "{\"VAR\": \"$TOKEN\"}"
    EOF

    delete = <<-EOF
        echo "$TOKEN" > delete.txt
        echo "{\"VAR\": \"$TOKEN\"}"
    EOF
  }
} 
scottwinkler commented 4 years ago

Okay i didn't understand what you were asking for before, but this makes sense. I like this a lot, thanks for your contribution.