terraform: test case for #11282

This commit is contained in:
Mitchell Hashimoto 2017-01-24 12:56:13 -08:00
parent 27e29420e5
commit 290ad37489
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
5 changed files with 56 additions and 0 deletions

View File

@ -553,6 +553,52 @@ func TestContext2Plan_moduleProviderInherit(t *testing.T) {
}
}
// This tests (for GH-11282) that deeply nested modules properly inherit
// configuration.
func TestContext2Plan_moduleProviderInheritDeep(t *testing.T) {
var l sync.Mutex
m := testModule(t, "plan-module-provider-inherit-deep")
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": func() (ResourceProvider, error) {
l.Lock()
defer l.Unlock()
var from string
p := testProvider("aws")
p.ConfigureFn = func(c *ResourceConfig) error {
v, ok := c.Get("from")
if !ok || v.(string) != "root" {
return fmt.Errorf("bad")
}
from = v.(string)
return nil
}
p.DiffFn = func(
info *InstanceInfo,
state *InstanceState,
c *ResourceConfig) (*InstanceDiff, error) {
if from != "root" {
return nil, fmt.Errorf("bad resource")
}
return testDiffFn(info, state, c)
}
return p, nil
},
},
})
_, err := ctx.Plan()
if err != nil {
t.Fatalf("err: %s", err)
}
}
func TestContext2Plan_moduleProviderDefaults(t *testing.T) {
var l sync.Mutex
var calls []string

View File

@ -0,0 +1 @@
module "B" { source = "../B" }

View File

@ -0,0 +1 @@
module "C" { source = "../C" }

View File

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

View File

@ -0,0 +1,7 @@
module "A" {
source = "./A"
}
provider "aws" {
from = "root"
}