terraform: get nested oprhans in the transform
This commit is contained in:
parent
96a04c16f6
commit
61d275f475
|
@ -2097,6 +2097,54 @@ func TestContext2Apply_destroy(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_destroyNestedModule(t *testing.T) {
|
||||
m := testModule(t, "apply-destroy-nested-module")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
|
||||
s := &State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: []string{"root", "child", "subchild"},
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.bar": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "bar",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ctx := testContext2(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
State: s,
|
||||
})
|
||||
|
||||
// First plan and apply a create operation
|
||||
if _, err := ctx.Plan(); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
// Test that things were destroyed
|
||||
actual := strings.TrimSpace(state.String())
|
||||
expected := strings.TrimSpace(testTerraformApplyDestroyNestedModuleStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_destroyOutputs(t *testing.T) {
|
||||
m := testModule(t, "apply-destroy-outputs")
|
||||
h := new(HookRecordApplyOrder)
|
||||
|
|
|
@ -483,6 +483,11 @@ const testTerraformApplyDestroyStr = `
|
|||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformApplyDestroyNestedModuleStr = `
|
||||
module.child.subchild:
|
||||
<no state>
|
||||
`
|
||||
|
||||
const testTerraformApplyErrorStr = `
|
||||
aws_instance.bar:
|
||||
ID = bar
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
module "subchild" {
|
||||
source = "./subchild"
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
resource "aws_instance" "bar" {}
|
|
@ -0,0 +1,5 @@
|
|||
/*
|
||||
module "child" {
|
||||
source = "./child"
|
||||
}
|
||||
*/
|
|
@ -100,9 +100,14 @@ func (t *OrphanTransformer) Transform(g *Graph) error {
|
|||
moduleOrphans := t.State.ModuleOrphans(g.Path, config)
|
||||
moduleVertexes := make([]dag.Vertex, len(moduleOrphans))
|
||||
for i, path := range moduleOrphans {
|
||||
var deps []string
|
||||
if s := t.State.ModuleByPath(path); s != nil {
|
||||
deps = s.Dependencies
|
||||
}
|
||||
|
||||
moduleVertexes[i] = g.Add(&graphNodeOrphanModule{
|
||||
Path: path,
|
||||
dependentOn: t.State.ModuleByPath(path).Dependencies,
|
||||
dependentOn: deps,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -356,3 +361,9 @@ func (n *graphNodeOrphanResourceFlat) CreateBeforeDestroy() bool {
|
|||
func (n *graphNodeOrphanResourceFlat) CreateNode() dag.Vertex {
|
||||
return n
|
||||
}
|
||||
|
||||
func (n *graphNodeOrphanResourceFlat) ProvidedBy() []string {
|
||||
return modulePrefixList(
|
||||
n.graphNodeOrphanResource.ProvidedBy(),
|
||||
modulePrefixStr(n.PathValue))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue