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.
This commit is contained in:
parent
83066cd57f
commit
bd6d3a638a
|
@ -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.
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue