Merge pull request #9318 from hashicorp/b-provider-orphan-grandchild

terraform: orphaned grandchild module inherits provider config
This commit is contained in:
Mitchell Hashimoto 2016-10-11 22:16:11 +08:00 committed by GitHub
commit 22c8a83031
2 changed files with 52 additions and 3 deletions

View File

@ -1390,6 +1390,54 @@ func TestContext2Apply_moduleOrphanProvider(t *testing.T) {
}
}
func TestContext2Apply_moduleOrphanGrandchildProvider(t *testing.T) {
m := testModule(t, "apply-module-orphan-provider-inherit")
p := testProvider("aws")
p.ApplyFn = testApplyFn
p.DiffFn = testDiffFn
p.ConfigureFn = func(c *ResourceConfig) error {
if _, ok := c.Get("value"); !ok {
return fmt.Errorf("value is not found")
}
return nil
}
// Create a state with an orphan module that is nested (grandchild)
state := &State{
Modules: []*ModuleState{
&ModuleState{
Path: []string{"root", "parent", "child"},
Resources: map[string]*ResourceState{
"aws_instance.bar": &ResourceState{
Type: "aws_instance",
Primary: &InstanceState{
ID: "bar",
},
},
},
},
},
}
ctx := testContext2(t, &ContextOpts{
Module: m,
State: state,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
if _, err := ctx.Plan(); err != nil {
t.Fatalf("err: %s", err)
}
if _, err := ctx.Apply(); err != nil {
t.Fatalf("err: %s", err)
}
}
func TestContext2Apply_moduleGrandchildProvider(t *testing.T) {
m := testModule(t, "apply-module-grandchild-provider-inherit")
p := testProvider("aws")

View File

@ -523,9 +523,10 @@ func (n *graphNodeProviderFlat) DependableName() []string {
func (n *graphNodeProviderFlat) DependentOn() []string {
var result []string
// If we're in a module, then depend on our parent's provider
if len(n.PathValue) > 1 {
prefix := modulePrefixStr(n.PathValue[:len(n.PathValue)-1])
// If we're in a module, then depend on all parent providers. Some of
// these may not exist, hence we depend on all of them.
for i := len(n.PathValue); i > 1; i-- {
prefix := modulePrefixStr(n.PathValue[:i-1])
result = modulePrefixList(n.graphNodeProvider.DependableName(), prefix)
}