terraform: fix provider config inheritance during input

The provider config was not being properly merged across module
boundaries during the Input walk over the graph, so when a provider was
configured at the top level, resources in modules could improperly
trigger a request for input for a provider attribute that's already
defined.
This commit is contained in:
Paul Hinze 2015-04-10 16:28:47 -05:00
parent 9f56addf0c
commit d1b40de242
6 changed files with 50 additions and 5 deletions

View File

@ -2927,6 +2927,35 @@ func TestContext2Input_providerVars(t *testing.T) {
}
}
func TestContext2Input_providerVarsModuleInherit(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "input-provider-with-vars-and-module")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
UIInput: input,
})
p.InputFn = func(i UIInput, c *ResourceConfig) (*ResourceConfig, error) {
if errs := c.CheckSet([]string{"access_key"}); len(errs) > 0 {
return c, errs[0]
}
return c, nil
}
p.ConfigureFn = func(c *ResourceConfig) error {
return nil
}
if err := ctx.Input(InputModeStd); err != nil {
t.Fatalf("err: %s", err)
}
}
func TestContext2Input_varOnly(t *testing.T) {
input := new(MockUIInput)
m := testModule(t, "input-provider-vars")

View File

@ -96,7 +96,7 @@ func (n *EvalGetProvider) Eval(ctx EvalContext) (interface{}, error) {
type EvalInputProvider struct {
Name string
Provider *ResourceProvider
Config *config.RawConfig
Config **ResourceConfig
}
func (n *EvalInputProvider) Eval(ctx EvalContext) (interface{}, error) {
@ -105,8 +105,7 @@ func (n *EvalInputProvider) Eval(ctx EvalContext) (interface{}, error) {
return nil, nil
}
rc := NewResourceConfig(n.Config)
rc.Config = make(map[string]interface{})
rc := *n.Config
// Wrap the input into a namespace
input := &PrefixUIInput{

View File

@ -22,10 +22,19 @@ func ProviderEvalTree(n string, config *config.RawConfig) EvalNode {
Name: n,
Output: &provider,
},
&EvalInterpolate{
Config: config,
Output: &resourceConfig,
},
&EvalBuildProviderConfig{
Provider: n,
Config: &resourceConfig,
Output: &resourceConfig,
},
&EvalInputProvider{
Name: n,
Provider: &provider,
Config: config,
Config: &resourceConfig,
},
},
},

View File

@ -0,0 +1 @@
resource "aws_instance" "foo" { }

View File

@ -0,0 +1,7 @@
provider "aws" {
access_key = "abc123"
}
module "child" {
source = "./child"
}

View File

@ -151,7 +151,7 @@ func (n *graphNodeDisabledProvider) EvalTree() EvalNode {
var resourceConfig *ResourceConfig
return &EvalOpFilter{
Ops: []walkOperation{walkValidate, walkRefresh, walkPlan, walkApply},
Ops: []walkOperation{walkInput, walkValidate, walkRefresh, walkPlan, walkApply},
Node: &EvalSequence{
Nodes: []EvalNode{
&EvalInterpolate{