terraform: Input should only be called on providers once

/cc @sethvargo

Prior to this commit, we'd only persist the result of calling Input if
any input was given (len(result) > 0). The result was that every module
would also repeat asking for input even if there was no input to be
asked for.

This commit makes it so that if no input was received, we still set a
sentinel so that modules don't re-ask.
This commit is contained in:
Mitchell Hashimoto 2015-02-20 15:35:57 -08:00
parent 09ea85a7c6
commit 40ee70d5c9
4 changed files with 38 additions and 1 deletions

View File

@ -2463,6 +2463,33 @@ func TestContext2Input_provider(t *testing.T) {
}
}
func TestContext2Input_providerOnce(t *testing.T) {
m := testModule(t, "input-provider-once")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
count := 0
p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) {
count++
return nil, nil
}
if err := ctx.Input(InputModeStd); err != nil {
t.Fatalf("err: %s", err)
}
if count != 1 {
t.Fatalf("should only be called once: %d", count)
}
}
func TestContext2Input_providerId(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "input-provider")

View File

@ -99,9 +99,12 @@ func (n *EvalInputProvider) Eval(ctx EvalContext) (interface{}, error) {
"Error configuring %s: %s", n.Name, err)
}
// Set the input that we received so that child modules don't attempt
// to ask for input again.
if config != nil && len(config.Config) > 0 {
// Set the configuration
ctx.SetProviderInput(n.Name, config.Config)
} else {
ctx.SetProviderInput(n.Name, map[string]interface{}{})
}
return nil, nil

View File

@ -0,0 +1,2 @@
provider "aws" {}
resource "aws_instance" "bar" {}

View File

@ -0,0 +1,5 @@
resource "aws_instance" "foo" {}
module "child" {
source = "./child"
}