you cannot refer to destroy nodes

Outputs and locals cannot refer to destroy nodes. Since those nodes
types do not have different ordering for create and destroy operations,
connecting them directly to destroy nodes can cause cycles.
This commit is contained in:
James Bardin 2020-07-17 18:48:35 -04:00
parent ca8338e343
commit 6f9d2c51e2
4 changed files with 5 additions and 30 deletions

View File

@ -55,7 +55,7 @@ func (n *nodeExpandLocal) ReferenceableAddrs() []addrs.Referenceable {
// GraphNodeReferencer // GraphNodeReferencer
func (n *nodeExpandLocal) References() []*addrs.Reference { func (n *nodeExpandLocal) References() []*addrs.Reference {
refs, _ := lang.ReferencesInExpr(n.Config.Expr) refs, _ := lang.ReferencesInExpr(n.Config.Expr)
return appendResourceDestroyReferences(refs) return refs
} }
func (n *nodeExpandLocal) DynamicExpand(ctx EvalContext) (*Graph, error) { func (n *nodeExpandLocal) DynamicExpand(ctx EvalContext) (*Graph, error) {
@ -117,7 +117,7 @@ func (n *NodeLocal) ReferenceableAddrs() []addrs.Referenceable {
// GraphNodeReferencer // GraphNodeReferencer
func (n *NodeLocal) References() []*addrs.Reference { func (n *NodeLocal) References() []*addrs.Reference {
refs, _ := lang.ReferencesInExpr(n.Config.Expr) refs, _ := lang.ReferencesInExpr(n.Config.Expr)
return appendResourceDestroyReferences(refs) return refs
} }
// GraphNodeEvalable // GraphNodeEvalable

View File

@ -68,7 +68,7 @@ func (n *nodeExpandModule) References() []*addrs.Reference {
forEachRefs, _ := lang.ReferencesInExpr(n.ModuleCall.ForEach) forEachRefs, _ := lang.ReferencesInExpr(n.ModuleCall.ForEach)
refs = append(refs, forEachRefs...) refs = append(refs, forEachRefs...)
} }
return appendResourceDestroyReferences(refs) return refs
} }
func (n *nodeExpandModule) DependsOn() []*addrs.Reference { func (n *nodeExpandModule) DependsOn() []*addrs.Reference {

View File

@ -96,7 +96,7 @@ func (n *nodeExpandOutput) ReferenceOutside() (selfPath, referencePath addrs.Mod
// GraphNodeReferencer // GraphNodeReferencer
func (n *nodeExpandOutput) References() []*addrs.Reference { func (n *nodeExpandOutput) References() []*addrs.Reference {
return appendResourceDestroyReferences(referencesForOutput(n.Config)) return referencesForOutput(n.Config)
} }
// NodeApplyableOutput represents an output that is "applyable": // NodeApplyableOutput represents an output that is "applyable":
@ -190,7 +190,7 @@ func referencesForOutput(c *configs.Output) []*addrs.Reference {
// GraphNodeReferencer // GraphNodeReferencer
func (n *NodeApplyableOutput) References() []*addrs.Reference { func (n *NodeApplyableOutput) References() []*addrs.Reference {
return appendResourceDestroyReferences(referencesForOutput(n.Config)) return referencesForOutput(n.Config)
} }
// GraphNodeEvalable // GraphNodeEvalable

View File

@ -501,31 +501,6 @@ func ReferencesFromConfig(body hcl.Body, schema *configschema.Block) []*addrs.Re
return refs return refs
} }
// appendResourceDestroyReferences identifies resource and resource instance
// references in the given slice and appends to it the "destroy-phase"
// equivalents of those references, returning the result.
//
// This can be used in the References implementation for a node which must also
// depend on the destruction of anything it references.
func appendResourceDestroyReferences(refs []*addrs.Reference) []*addrs.Reference {
given := refs
for _, ref := range given {
switch tr := ref.Subject.(type) {
case addrs.Resource:
newRef := *ref // shallow copy
newRef.Subject = tr.Phase(addrs.ResourceInstancePhaseDestroy)
refs = append(refs, &newRef)
case addrs.ResourceInstance:
newRef := *ref // shallow copy
newRef.Subject = tr.Phase(addrs.ResourceInstancePhaseDestroy)
refs = append(refs, &newRef)
}
// FIXME: Using this method in module expansion references,
// May want to refactor this method beyond resources
}
return refs
}
func modulePrefixStr(p addrs.ModuleInstance) string { func modulePrefixStr(p addrs.ModuleInstance) string {
return p.String() return p.String()
} }