terraform: all providers for ProvidedBy() should be added
This commit is contained in:
parent
594f04e064
commit
51a7e05f8a
|
@ -4358,6 +4358,43 @@ func TestContext2Apply_moduleOrphanProvider(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This tests an issue where all the providers in a module but not
|
||||||
|
// in the root weren't being added to the root properly. In this test
|
||||||
|
// case: aws is explicitly added to root, but "test" should be added to.
|
||||||
|
// With the bug, it wasn't.
|
||||||
|
func TestContext2Apply_moduleOnlyProvider(t *testing.T) {
|
||||||
|
m := testModule(t, "apply-module-only-provider")
|
||||||
|
p := testProvider("aws")
|
||||||
|
p.ApplyFn = testApplyFn
|
||||||
|
p.DiffFn = testDiffFn
|
||||||
|
pTest := testProvider("test")
|
||||||
|
pTest.ApplyFn = testApplyFn
|
||||||
|
pTest.DiffFn = testDiffFn
|
||||||
|
|
||||||
|
ctx := testContext2(t, &ContextOpts{
|
||||||
|
Module: m,
|
||||||
|
Providers: map[string]ResourceProviderFactory{
|
||||||
|
"aws": testProviderFuncFixed(p),
|
||||||
|
"test": testProviderFuncFixed(pTest),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if _, err := ctx.Plan(); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
state, err := ctx.Apply()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := strings.TrimSpace(state.String())
|
||||||
|
expected := strings.TrimSpace(testTerraformApplyModuleOnlyProviderStr)
|
||||||
|
if actual != expected {
|
||||||
|
t.Fatalf("bad: \n%s", actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestContext2Apply_moduleProviderAlias(t *testing.T) {
|
func TestContext2Apply_moduleProviderAlias(t *testing.T) {
|
||||||
m := testModule(t, "apply-module-provider-alias")
|
m := testModule(t, "apply-module-provider-alias")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
|
@ -379,6 +379,15 @@ do_instance.foo:
|
||||||
type = do_instance
|
type = do_instance
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testTerraformApplyModuleOnlyProviderStr = `
|
||||||
|
<no state>
|
||||||
|
module.child:
|
||||||
|
aws_instance.foo:
|
||||||
|
ID = foo
|
||||||
|
test_instance.foo:
|
||||||
|
ID = foo
|
||||||
|
`
|
||||||
|
|
||||||
const testTerraformApplyModuleProviderAliasStr = `
|
const testTerraformApplyModuleProviderAliasStr = `
|
||||||
<no state>
|
<no state>
|
||||||
module.child:
|
module.child:
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
resource "aws_instance" "foo" {}
|
||||||
|
resource "test_instance" "foo" {}
|
|
@ -0,0 +1,5 @@
|
||||||
|
provider "aws" {}
|
||||||
|
|
||||||
|
module "child" {
|
||||||
|
source = "./child"
|
||||||
|
}
|
|
@ -167,7 +167,7 @@ func (t *MissingProviderTransformer) Transform(g *Graph) error {
|
||||||
for _, p := range pv.ProvidedBy() {
|
for _, p := range pv.ProvidedBy() {
|
||||||
if _, ok := m[p]; ok {
|
if _, ok := m[p]; ok {
|
||||||
// This provider already exists as a configure node
|
// This provider already exists as a configure node
|
||||||
break
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the provider has an alias in it, we just want the type
|
// If the provider has an alias in it, we just want the type
|
||||||
|
|
Loading…
Reference in New Issue