index destroy dependencies by addrs.ConfigResource

When the DestroyEdgeTransformer was updated to handle stored
dependencies the addrs.ConfigResource type did not yet exist. The lookup
map keys in the transformer needed to be updated to remove module
indexes.
This commit is contained in:
James Bardin 2020-06-25 15:23:00 -04:00
parent 6ef11e9d9e
commit 9f7b3cc1dc
2 changed files with 15 additions and 14 deletions

View File

@ -62,9 +62,10 @@ func (t *DestroyEdgeTransformer) Transform(g *Graph) error {
// are only being updated. // are only being updated.
creators := make(map[string]GraphNodeCreator) creators := make(map[string]GraphNodeCreator)
// destroyersByResource records each destroyer by the AbsResourceAddress. // destroyersByResource records each destroyer by the ConfigResource
// We use this because dependencies are only referenced as resources, but we // address. We use this because dependencies are only referenced as
// will want to connect all the individual instances for correct ordering. // resources and have no index or module instance information, but we will
// want to connect all the individual instances for correct ordering.
destroyersByResource := make(map[string][]GraphNodeDestroyer) destroyersByResource := make(map[string][]GraphNodeDestroyer)
for _, v := range g.Vertices() { for _, v := range g.Vertices() {
switch n := v.(type) { switch n := v.(type) {
@ -80,7 +81,7 @@ func (t *DestroyEdgeTransformer) Transform(g *Graph) error {
log.Printf("[TRACE] DestroyEdgeTransformer: %q (%T) destroys %s", dag.VertexName(n), v, key) log.Printf("[TRACE] DestroyEdgeTransformer: %q (%T) destroys %s", dag.VertexName(n), v, key)
destroyers[key] = append(destroyers[key], n) destroyers[key] = append(destroyers[key], n)
resAddr := addr.Resource.Resource.Absolute(addr.Module).String() resAddr := addr.ContainingResource().Config().String()
destroyersByResource[resAddr] = append(destroyersByResource[resAddr], n) destroyersByResource[resAddr] = append(destroyersByResource[resAddr], n)
case GraphNodeCreator: case GraphNodeCreator:
addr := n.CreateAddr() addr := n.CreateAddr()

View File

@ -172,12 +172,12 @@ func TestDestroyEdgeTransformer_module(t *testing.T) {
func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) { func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) {
g := Graph{Path: addrs.RootModuleInstance} g := Graph{Path: addrs.RootModuleInstance}
g.Add(testDestroyNode("module.child.test_object.a")) g.Add(testDestroyNode("module.child[0].test_object.a"))
g.Add(testDestroyNode("module.child.test_object.b")) g.Add(testDestroyNode("module.child[0].test_object.b"))
g.Add(testDestroyNode("module.child.test_object.c")) g.Add(testDestroyNode("module.child[0].test_object.c"))
state := states.NewState() state := states.NewState()
child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.NoKey)) child := state.EnsureModule(addrs.RootModuleInstance.Child("child", addrs.IntKey(0)))
child.SetResourceInstanceCurrent( child.SetResourceInstanceCurrent(
mustResourceInstanceAddr("test_object.a").Resource, mustResourceInstanceAddr("test_object.a").Resource,
&states.ResourceInstanceObjectSrc{ &states.ResourceInstanceObjectSrc{
@ -222,12 +222,12 @@ func TestDestroyEdgeTransformer_moduleOnly(t *testing.T) {
actual := strings.TrimSpace(g.String()) actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(` expected := strings.TrimSpace(`
module.child.test_object.a (destroy) module.child[0].test_object.a (destroy)
module.child.test_object.b (destroy) module.child[0].test_object.b (destroy)
module.child.test_object.c (destroy) module.child[0].test_object.c (destroy)
module.child.test_object.b (destroy) module.child[0].test_object.b (destroy)
module.child.test_object.c (destroy) module.child[0].test_object.c (destroy)
module.child.test_object.c (destroy) module.child[0].test_object.c (destroy)
`) `)
if actual != expected { if actual != expected {
t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected) t.Fatalf("wrong result\n\ngot:\n%s\n\nwant:\n%s", actual, expected)