From bd6d3a638a714505b9608e62039921bb00cd01e9 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 13 Sep 2018 16:14:16 -0700 Subject: [PATCH] core: Simplify output refs to module call refs in StateReferences As previously mentioned in a comment here, versions of Terraform prior to 0.12 would store references to module outputs as just references to the module as a whole in the state. It's not really clear why, but we wanted to preserve this behavior for 0.12. The previous implementation actually failed to do so, in spite of the comment, so this commit fixes it to actually do what the comment originally claimed. In a later release we might remove this special case and just depend directly on outputs where possible, since that'd allow us to produce a more precise dependency graph for destroy actions, but when we do that we'll first need to confirm that there isn't a good reason for the original exception here. --- terraform/node_resource_abstract.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/terraform/node_resource_abstract.go b/terraform/node_resource_abstract.go index de8082f41..044bf45b2 100644 --- a/terraform/node_resource_abstract.go +++ b/terraform/node_resource_abstract.go @@ -282,12 +282,21 @@ func (n *NodeAbstractResource) StateReferences() []addrs.Referenceable { depsRaw := n.References() deps := make([]addrs.Referenceable, 0, len(depsRaw)) for _, d := range depsRaw { - k := d.Subject.String() + subj := d.Subject + if mco, isOutput := subj.(addrs.ModuleCallOutput); isOutput { + // For state dependencies, we simplify outputs to just refer + // to the module as a whole. It's not really clear why we do this, + // but this logic is preserved from before the 0.12 rewrite of + // this function. + subj = mco.Call + } + + k := subj.String() if _, exists := seen[k]; exists { continue } seen[k] = struct{}{} - switch tr := d.Subject.(type) { + switch tr := subj.(type) { case addrs.ResourceInstance: deps = append(deps, tr) case addrs.Resource: @@ -304,12 +313,6 @@ func (n *NodeAbstractResource) StateReferences() []addrs.Referenceable { } case addrs.ModuleCallInstance: deps = append(deps, tr) - case addrs.ModuleCallOutput: - // For state dependencies, we simplify outputs to just refer - // to the module as a whole. It's not really clear why we do this, - // but this logic is preserved from before the 0.12 rewrite of - // this function. - deps = append(deps, tr) default: // No other reference types are recorded in the state. }