From 6f9d2c51e2d09ff4add417bd0a7e5a879864a173 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Fri, 17 Jul 2020 18:48:35 -0400 Subject: [PATCH] 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. --- terraform/node_local.go | 4 ++-- terraform/node_module_expand.go | 2 +- terraform/node_output.go | 4 ++-- terraform/transform_reference.go | 25 ------------------------- 4 files changed, 5 insertions(+), 30 deletions(-) diff --git a/terraform/node_local.go b/terraform/node_local.go index 6be28b036..8924d5336 100644 --- a/terraform/node_local.go +++ b/terraform/node_local.go @@ -55,7 +55,7 @@ func (n *nodeExpandLocal) ReferenceableAddrs() []addrs.Referenceable { // GraphNodeReferencer func (n *nodeExpandLocal) References() []*addrs.Reference { refs, _ := lang.ReferencesInExpr(n.Config.Expr) - return appendResourceDestroyReferences(refs) + return refs } func (n *nodeExpandLocal) DynamicExpand(ctx EvalContext) (*Graph, error) { @@ -117,7 +117,7 @@ func (n *NodeLocal) ReferenceableAddrs() []addrs.Referenceable { // GraphNodeReferencer func (n *NodeLocal) References() []*addrs.Reference { refs, _ := lang.ReferencesInExpr(n.Config.Expr) - return appendResourceDestroyReferences(refs) + return refs } // GraphNodeEvalable diff --git a/terraform/node_module_expand.go b/terraform/node_module_expand.go index 330f3e674..be65768d5 100644 --- a/terraform/node_module_expand.go +++ b/terraform/node_module_expand.go @@ -68,7 +68,7 @@ func (n *nodeExpandModule) References() []*addrs.Reference { forEachRefs, _ := lang.ReferencesInExpr(n.ModuleCall.ForEach) refs = append(refs, forEachRefs...) } - return appendResourceDestroyReferences(refs) + return refs } func (n *nodeExpandModule) DependsOn() []*addrs.Reference { diff --git a/terraform/node_output.go b/terraform/node_output.go index 6c3713fd1..4301a755e 100644 --- a/terraform/node_output.go +++ b/terraform/node_output.go @@ -96,7 +96,7 @@ func (n *nodeExpandOutput) ReferenceOutside() (selfPath, referencePath addrs.Mod // GraphNodeReferencer func (n *nodeExpandOutput) References() []*addrs.Reference { - return appendResourceDestroyReferences(referencesForOutput(n.Config)) + return referencesForOutput(n.Config) } // NodeApplyableOutput represents an output that is "applyable": @@ -190,7 +190,7 @@ func referencesForOutput(c *configs.Output) []*addrs.Reference { // GraphNodeReferencer func (n *NodeApplyableOutput) References() []*addrs.Reference { - return appendResourceDestroyReferences(referencesForOutput(n.Config)) + return referencesForOutput(n.Config) } // GraphNodeEvalable diff --git a/terraform/transform_reference.go b/terraform/transform_reference.go index 2e608b370..a5f21246e 100644 --- a/terraform/transform_reference.go +++ b/terraform/transform_reference.go @@ -501,31 +501,6 @@ func ReferencesFromConfig(body hcl.Body, schema *configschema.Block) []*addrs.Re 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 { return p.String() }