diff --git a/config/loader_libucl.go b/config/loader_libucl.go index 15bceca41..9eea02a21 100644 --- a/config/loader_libucl.go +++ b/config/loader_libucl.go @@ -48,22 +48,24 @@ func (t *libuclConfigurable) Config() (*Config, error) { // TODO(mitchellh): Make function like loadVariablesLibucl so that // duplicates aren't overriden config := new(Config) - config.Variables = make([]*Variable, 0, len(rawConfig.Variable)) - for k, v := range rawConfig.Variable { - defaultSet := false - for _, f := range v.Fields { - if f == "Default" { - defaultSet = true - break + if len(rawConfig.Variable) > 0 { + config.Variables = make([]*Variable, 0, len(rawConfig.Variable)) + for k, v := range rawConfig.Variable { + defaultSet := false + for _, f := range v.Fields { + if f == "Default" { + defaultSet = true + break + } } - } - config.Variables = append(config.Variables, &Variable{ - Name: k, - Default: v.Default, - Description: v.Description, - defaultSet: defaultSet, - }) + config.Variables = append(config.Variables, &Variable{ + Name: k, + Default: v.Default, + Description: v.Description, + defaultSet: defaultSet, + }) + } } // Build the provider configs diff --git a/config/merge.go b/config/merge.go index 3d7a54794..e8c8dff5c 100644 --- a/config/merge.go +++ b/config/merge.go @@ -26,26 +26,28 @@ func Merge(c1, c2 *Config) (*Config, error) { // Merge variables: Variable merging is quite simple. Set fields in // later set variables override those earlier. - c.Variables = make([]*Variable, 0, len(c1.Variables)+len(c2.Variables)) - varMap := make(map[string]*Variable) - for _, v := range c1.Variables { - varMap[v.Name] = v - } - for _, v2 := range c2.Variables { - v1, ok := varMap[v2.Name] - if ok { - if v2.Default == "" { - v2.Default = v1.Default - } - if v2.Description == "" { - v2.Description = v1.Description - } + if len(c1.Variables) > 0 || len(c2.Variables) > 0 { + c.Variables = make([]*Variable, 0, len(c1.Variables)+len(c2.Variables)) + varMap := make(map[string]*Variable) + for _, v := range c1.Variables { + varMap[v.Name] = v } + for _, v2 := range c2.Variables { + v1, ok := varMap[v2.Name] + if ok { + if v2.Default == "" { + v2.Default = v1.Default + } + if v2.Description == "" { + v2.Description = v1.Description + } + } - varMap[v2.Name] = v2 - } - for _, v := range varMap { - c.Variables = append(c.Variables, v) + varMap[v2.Name] = v2 + } + for _, v := range varMap { + c.Variables = append(c.Variables, v) + } } // Merge outputs: If they collide, just take the latest one for now. In diff --git a/terraform/plan_test.go b/terraform/plan_test.go index 8a9a28810..59690e4f1 100644 --- a/terraform/plan_test.go +++ b/terraform/plan_test.go @@ -53,6 +53,8 @@ func TestReadWritePlan(t *testing.T) { t.Fatalf("err: %s", err) } + println(reflect.DeepEqual(actual.Config.Variables, plan.Config.Variables)) + if !reflect.DeepEqual(actual, plan) { t.Fatalf("bad: %#v", actual) } diff --git a/terraform/semantics.go b/terraform/semantics.go index 0a40506fd..21b8199e8 100644 --- a/terraform/semantics.go +++ b/terraform/semantics.go @@ -13,9 +13,9 @@ func smcUserVariables(c *config.Config, vs map[string]string) []error { // Check that all required variables are present required := make(map[string]struct{}) - for k, v := range c.Variables { + for _, v := range c.Variables { if v.Required() { - required[k] = struct{}{} + required[v.Name] = struct{}{} } } for k, _ := range vs {