From c827c049fe688f3ad2b705aa1adf8a72bbcec37c Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 20 Nov 2020 15:10:08 -0800 Subject: [PATCH] terraform: Precondition and postcondition blocks generate dependencies If a resource or output value has a precondition or postcondition rule then anything the condition depends on is a dependency of the object, because the condition rules will be evaluated as part of visiting the relevant graph node. --- internal/terraform/node_output.go | 5 ++++- internal/terraform/node_resource_abstract.go | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/internal/terraform/node_output.go b/internal/terraform/node_output.go index 93ff30aae..0532a3d61 100644 --- a/internal/terraform/node_output.go +++ b/internal/terraform/node_output.go @@ -237,8 +237,11 @@ func referencesForOutput(c *configs.Output) []*addrs.Reference { refs := make([]*addrs.Reference, 0, l) refs = append(refs, impRefs...) refs = append(refs, expRefs...) + for _, check := range c.Preconditions { + checkRefs, _ := lang.ReferencesInExpr(check.Condition) + refs = append(refs, checkRefs...) + } return refs - } // GraphNodeReferencer diff --git a/internal/terraform/node_resource_abstract.go b/internal/terraform/node_resource_abstract.go index fb3f4a945..bc22d4be7 100644 --- a/internal/terraform/node_resource_abstract.go +++ b/internal/terraform/node_resource_abstract.go @@ -172,6 +172,16 @@ func (n *NodeAbstractResource) References() []*addrs.Reference { result = append(result, refs...) } } + + for _, check := range c.Preconditions { + refs, _ := lang.ReferencesInExpr(check.Condition) + result = append(result, refs...) + } + for _, check := range c.Postconditions { + refs, _ := lang.ReferencesInExpr(check.Condition) + result = append(result, refs...) + } + return result }