Merge pull request #11929 from hashicorp/f-terraformrc-env

terraformrc can contain env var references
This commit is contained in:
Mitchell Hashimoto 2017-02-16 08:57:16 -08:00 committed by GitHub
commit d8e3fac92c
3 changed files with 41 additions and 0 deletions

View File

@ -74,6 +74,14 @@ func LoadConfig(path string) (*Config, error) {
return nil, err
}
// Replace all env vars
for k, v := range result.Providers {
result.Providers[k] = os.ExpandEnv(v)
}
for k, v := range result.Provisioners {
result.Provisioners[k] = os.ExpandEnv(v)
}
return &result, nil
}

View File

@ -1,6 +1,7 @@
package main
import (
"os"
"path/filepath"
"reflect"
"testing"
@ -27,6 +28,30 @@ func TestLoadConfig(t *testing.T) {
}
}
func TestLoadConfig_env(t *testing.T) {
defer os.Unsetenv("TFTEST")
os.Setenv("TFTEST", "hello")
c, err := LoadConfig(filepath.Join(fixtureDir, "config-env"))
if err != nil {
t.Fatalf("err: %s", err)
}
expected := &Config{
Providers: map[string]string{
"aws": "hello",
"google": "bar",
},
Provisioners: map[string]string{
"local": "hello",
},
}
if !reflect.DeepEqual(c, expected) {
t.Fatalf("bad: %#v", c)
}
}
func TestConfig_Merge(t *testing.T) {
c1 := &Config{
Providers: map[string]string{

8
test-fixtures/config-env Normal file
View File

@ -0,0 +1,8 @@
providers {
aws = "$TFTEST"
google = "bar"
}
provisioners {
local = "$TFTEST"
}