terraform: tests passing for Config change

This commit is contained in:
Mitchell Hashimoto 2014-07-18 22:13:15 -07:00
parent e4bcd3c448
commit a19e2983de
4 changed files with 40 additions and 34 deletions

View File

@ -48,6 +48,7 @@ func (t *libuclConfigurable) Config() (*Config, error) {
// TODO(mitchellh): Make function like loadVariablesLibucl so that
// duplicates aren't overriden
config := new(Config)
if len(rawConfig.Variable) > 0 {
config.Variables = make([]*Variable, 0, len(rawConfig.Variable))
for k, v := range rawConfig.Variable {
defaultSet := false
@ -65,6 +66,7 @@ func (t *libuclConfigurable) Config() (*Config, error) {
defaultSet: defaultSet,
})
}
}
// Build the provider configs
providers := t.Object.Get("provider")

View File

@ -26,6 +26,7 @@ func Merge(c1, c2 *Config) (*Config, error) {
// Merge variables: Variable merging is quite simple. Set fields in
// later set variables override those earlier.
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 {
@ -47,6 +48,7 @@ func Merge(c1, c2 *Config) (*Config, error) {
for _, v := range varMap {
c.Variables = append(c.Variables, v)
}
}
// Merge outputs: If they collide, just take the latest one for now. In
// the future, we might provide smarter merge functionality.

View File

@ -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)
}

View File

@ -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 {