Browse Source

Fix parsing values containing = from os environment

pull/46/head
Jacob McCann 7 years ago
parent
commit
9749b0b8f9
  1. 2
      plugin.go
  2. 2
      plugin_test.go

2
plugin.go

@ -110,7 +110,7 @@ func installCaCert(cacert string) *exec.Cmd {
func CopyTfEnv() {
tfVar := regexp.MustCompile(`^TF_VAR_.*$`)
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
pair := strings.SplitN(e, "=", 2)
if tfVar.MatchString(pair[0]) {
name := strings.Split(pair[0], "TF_VAR_")
os.Setenv(fmt.Sprintf("TF_VAR_%s", strings.ToLower(name[1])), pair[1])

2
plugin_test.go

@ -143,12 +143,14 @@ func TestPlugin(t *testing.T) {
// Set some initial TF_VAR_ that are uppercase
os.Setenv("TF_VAR_SOMETHING", "some value")
os.Setenv("TF_VAR_SOMETHING_ELSE", "some other value")
os.Setenv("TF_VAR_BASE64", "dGVzdA==")
CopyTfEnv()
// Make sure new env vars exist with proper values
g.Assert(os.Getenv("TF_VAR_something")).Equal("some value")
g.Assert(os.Getenv("TF_VAR_something_else")).Equal("some other value")
g.Assert(os.Getenv("TF_VAR_base64")).Equal("dGVzdA==")
})
})
}

Loading…
Cancel
Save