From 13a6625b51264f62358591259f888ff1b7505d98 Mon Sep 17 00:00:00 2001 From: Caio Quirino da Silva Date: Mon, 22 Jul 2019 15:16:20 +0200 Subject: [PATCH] Override environment variables only when changed When using Command.Env, if you send nil as a value, it will use all of the environment variables from os.Environ() when executing the command. In order to not break the current tests and be coherent with the current relationship, we are appending the created environment variables with os.Environ() only when we have at least 1 environment variable to override. --- plugin.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin.go b/plugin.go index bea2f13..af81e14 100644 --- a/plugin.go +++ b/plugin.go @@ -382,7 +382,10 @@ func createEnvironmentVariables(config Config) []string { func createTerraformCommand(config Config, args ...string) *exec.Cmd { command := exec.Command("terraform", args...) - command.Env = append(command.Env, createEnvironmentVariables(config)...) + environmentVariables := createEnvironmentVariables(config) + if len(environmentVariables) > 0 { + command.Env = append(os.Environ(), environmentVariables...) + } return command } func getTfoutPath(config Config) string {