From 813094893603f824c6a834721deaf17da51a5a62 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 19 Sep 2018 21:30:16 -0400 Subject: [PATCH] make NodePlannableResource eval-able Eval a NodePlannableResource before expanding it, to ensure that it can be referenced even if the count is 0. --- terraform/node_resource_plan.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/terraform/node_resource_plan.go b/terraform/node_resource_plan.go index 7b185cebb..1d15b0503 100644 --- a/terraform/node_resource_plan.go +++ b/terraform/node_resource_plan.go @@ -1,6 +1,8 @@ package terraform import ( + "log" + "github.com/hashicorp/terraform/dag" "github.com/hashicorp/terraform/tfdiags" ) @@ -20,6 +22,25 @@ var ( _ GraphNodeAttachResourceConfig = (*NodePlannableResource)(nil) ) +// GraphNodeEvalable +func (n *NodePlannableResource) EvalTree() EvalNode { + addr := n.ResourceAddr() + config := n.Config + + if config == nil { + // Nothing to do, then. + log.Printf("[TRACE] NodeApplyableResource: no configuration present for %s", addr) + return &EvalNoop{} + } + + // this ensures we can reference the resource even if the count is 0 + return &EvalWriteResourceState{ + Addr: addr.Resource, + Config: config, + ProviderAddr: n.ResolvedProvider, + } +} + // GraphNodeDynamicExpandable func (n *NodePlannableResource) DynamicExpand(ctx EvalContext) (*Graph, error) { var diags tfdiags.Diagnostics