terraform: input properly sends on only set input

This commit is contained in:
Mitchell Hashimoto 2014-10-18 14:54:42 -07:00
parent dc3178e06a
commit 686871310d
5 changed files with 25 additions and 20 deletions

View File

@ -346,7 +346,7 @@ func (m schemaMap) Input(
"%s: %s", k, err)
}
c.Raw[k] = value
c.Config[k] = value
}
return c, nil

View File

@ -1413,9 +1413,7 @@ func TestSchemaMap_Input(t *testing.T) {
"availability_zone": "foo",
},
Result: map[string]interface{}{
"availability_zone": "bar",
},
Result: map[string]interface{}{},
Err: false,
},
@ -1494,14 +1492,16 @@ func TestSchemaMap_Input(t *testing.T) {
input := new(terraform.MockUIInput)
input.InputReturnMap = tc.Input
actual, err := schemaMap(tc.Schema).Input(
input, terraform.NewResourceConfig(c))
rc := terraform.NewResourceConfig(c)
rc.Config = make(map[string]interface{})
actual, err := schemaMap(tc.Schema).Input(input, rc)
if (err != nil) != tc.Err {
t.Fatalf("#%d err: %s", i, err)
}
if !reflect.DeepEqual(tc.Result, actual.Raw) {
t.Fatalf("#%d: bad:\n\n%#v", i, actual.Raw)
if !reflect.DeepEqual(tc.Result, actual.Config) {
t.Fatalf("#%d: bad:\n\n%#v", i, actual.Config)
}
}
}

View File

@ -600,6 +600,7 @@ func (c *walkContext) inputWalkFn() depgraph.WalkFunc {
raw = sharedProvider.Config.RawConfig
}
rc := NewResourceConfig(raw)
rc.Config = make(map[string]interface{})
// Wrap the input into a namespace
input := &PrefixUIInput{
@ -617,8 +618,8 @@ func (c *walkContext) inputWalkFn() depgraph.WalkFunc {
return fmt.Errorf(
"Error configuring %s: %s", k, err)
}
if newc != nil {
configs[k] = newc.Raw
if newc != nil && len(newc.Config) > 0 {
configs[k] = newc.Config
}
}

View File

@ -647,11 +647,11 @@ func TestContextInput_provider(t *testing.T) {
var actual interface{}
p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) {
c.Raw["foo"] = "bar"
c.Config["foo"] = "bar"
return c, nil
}
p.ConfigureFn = func(c *ResourceConfig) error {
actual = c.Raw["foo"]
actual = c.Config["foo"]
return nil
}
@ -693,11 +693,11 @@ func TestContextInput_providerId(t *testing.T) {
return nil, err
}
c.Raw["foo"] = v
c.Config["foo"] = v
return c, nil
}
p.ConfigureFn = func(c *ResourceConfig) error {
actual = c.Raw["foo"]
actual = c.Config["foo"]
return nil
}
@ -745,11 +745,11 @@ func TestContextInput_providerOnly(t *testing.T) {
var actual interface{}
p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) {
c.Raw["foo"] = "bar"
c.Config["foo"] = "bar"
return c, nil
}
p.ConfigureFn = func(c *ResourceConfig) error {
actual = c.Raw["foo"]
actual = c.Config["foo"]
return nil
}
@ -794,10 +794,13 @@ func TestContextInput_providerVars(t *testing.T) {
UIInput: input,
})
input.InputReturnMap = map[string]string{}
input.InputReturnMap = map[string]string{
"var.foo": "bar",
}
var actual interface{}
p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) {
c.Config["bar"] = "baz"
return c, nil
}
p.ConfigureFn = func(c *ResourceConfig) error {

View File

@ -1594,14 +1594,15 @@ func graphRemoveInvalidDeps(g *depgraph.Graph) {
func (p *graphSharedProvider) MergeConfig(
raw bool, override map[string]interface{}) *ResourceConfig {
var rawMap map[string]interface{}
if override != nil {
rawMap = override
} else if p.Config != nil {
if p.Config != nil {
rawMap = p.Config.RawConfig.Config()
}
if rawMap == nil {
rawMap = make(map[string]interface{})
}
for k, v := range override {
rawMap[k] = v
}
// Merge in all the parent configurations
if p.Parent != nil {