mirror of
https://github.com/thegeeklab/wp-opentofu.git
synced 2024-11-22 00:30:40 +00:00
Fix parsing values containing = from os environment
This commit is contained in:
parent
69e77144a1
commit
9749b0b8f9
@ -110,7 +110,7 @@ func installCaCert(cacert string) *exec.Cmd {
|
|||||||
func CopyTfEnv() {
|
func CopyTfEnv() {
|
||||||
tfVar := regexp.MustCompile(`^TF_VAR_.*$`)
|
tfVar := regexp.MustCompile(`^TF_VAR_.*$`)
|
||||||
for _, e := range os.Environ() {
|
for _, e := range os.Environ() {
|
||||||
pair := strings.Split(e, "=")
|
pair := strings.SplitN(e, "=", 2)
|
||||||
if tfVar.MatchString(pair[0]) {
|
if tfVar.MatchString(pair[0]) {
|
||||||
name := strings.Split(pair[0], "TF_VAR_")
|
name := strings.Split(pair[0], "TF_VAR_")
|
||||||
os.Setenv(fmt.Sprintf("TF_VAR_%s", strings.ToLower(name[1])), pair[1])
|
os.Setenv(fmt.Sprintf("TF_VAR_%s", strings.ToLower(name[1])), pair[1])
|
||||||
|
@ -143,12 +143,14 @@ func TestPlugin(t *testing.T) {
|
|||||||
// Set some initial TF_VAR_ that are uppercase
|
// Set some initial TF_VAR_ that are uppercase
|
||||||
os.Setenv("TF_VAR_SOMETHING", "some value")
|
os.Setenv("TF_VAR_SOMETHING", "some value")
|
||||||
os.Setenv("TF_VAR_SOMETHING_ELSE", "some other value")
|
os.Setenv("TF_VAR_SOMETHING_ELSE", "some other value")
|
||||||
|
os.Setenv("TF_VAR_BASE64", "dGVzdA==")
|
||||||
|
|
||||||
CopyTfEnv()
|
CopyTfEnv()
|
||||||
|
|
||||||
// Make sure new env vars exist with proper values
|
// 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")).Equal("some value")
|
||||||
g.Assert(os.Getenv("TF_VAR_something_else")).Equal("some other value")
|
g.Assert(os.Getenv("TF_VAR_something_else")).Equal("some other value")
|
||||||
|
g.Assert(os.Getenv("TF_VAR_base64")).Equal("dGVzdA==")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user