Merge pull request #2476 from hashicorp/b-orphan-provider-inherit
terraform: module orphans providers should inherit config
This commit is contained in:
commit
632cc92897
|
@ -4392,6 +4392,54 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContext2Apply_moduleOrphanProvider(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
|
||||||
|
state := &State{
|
||||||
|
Modules: []*ModuleState{
|
||||||
|
&ModuleState{
|
||||||
|
Path: []string{"root", "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_moduleVarResourceCount(t *testing.T) {
|
func TestContext2Apply_moduleVarResourceCount(t *testing.T) {
|
||||||
m := testModule(t, "apply-module-var-resource-count")
|
m := testModule(t, "apply-module-var-resource-count")
|
||||||
p := testProvider("aws")
|
p := testProvider("aws")
|
||||||
|
|
|
@ -117,14 +117,12 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
|
||||||
&MissingProviderTransformer{Providers: b.Providers},
|
&MissingProviderTransformer{Providers: b.Providers},
|
||||||
&ProviderTransformer{},
|
&ProviderTransformer{},
|
||||||
&CloseProviderTransformer{},
|
&CloseProviderTransformer{},
|
||||||
&PruneProviderTransformer{},
|
|
||||||
&DisableProviderTransformer{},
|
&DisableProviderTransformer{},
|
||||||
|
|
||||||
// Provisioner-related transformations
|
// Provisioner-related transformations
|
||||||
&MissingProvisionerTransformer{Provisioners: b.Provisioners},
|
&MissingProvisionerTransformer{Provisioners: b.Provisioners},
|
||||||
&ProvisionerTransformer{},
|
&ProvisionerTransformer{},
|
||||||
&CloseProvisionerTransformer{},
|
&CloseProvisionerTransformer{},
|
||||||
&PruneProvisionerTransformer{},
|
|
||||||
|
|
||||||
// Run our vertex-level transforms
|
// Run our vertex-level transforms
|
||||||
&VertexTransformer{
|
&VertexTransformer{
|
||||||
|
@ -154,6 +152,12 @@ func (b *BuiltinGraphBuilder) Steps(path []string) []GraphTransformer {
|
||||||
// We don't do the following for modules.
|
// We don't do the following for modules.
|
||||||
if len(path) <= 1 {
|
if len(path) <= 1 {
|
||||||
steps = append(steps,
|
steps = append(steps,
|
||||||
|
// Prune the providers and provisioners. This must happen
|
||||||
|
// only once because flattened modules might depend on empty
|
||||||
|
// providers.
|
||||||
|
&PruneProviderTransformer{},
|
||||||
|
&PruneProvisionerTransformer{},
|
||||||
|
|
||||||
// Create the destruction nodes
|
// Create the destruction nodes
|
||||||
&DestroyTransformer{FullDestroy: b.Destroy},
|
&DestroyTransformer{FullDestroy: b.Destroy},
|
||||||
&CreateBeforeDestroyTransformer{},
|
&CreateBeforeDestroyTransformer{},
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
provider "aws" {
|
||||||
|
value = "foo"
|
||||||
|
}
|
Loading…
Reference in New Issue