From 745d4e76ec211d4160e8eae0a019ea3628a617ec Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 19 Feb 2020 16:54:41 -0500 Subject: [PATCH] better comments --- terraform/eval_apply.go | 5 ++++- terraform/evaluate.go | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/terraform/eval_apply.go b/terraform/eval_apply.go index 5be883197..0755c6b9f 100644 --- a/terraform/eval_apply.go +++ b/terraform/eval_apply.go @@ -563,7 +563,10 @@ func (n *EvalApplyProvisioners) apply(ctx EvalContext, provs []*configs.Provisio var forEach map[string]cty.Value - // We can't evaluate the for_each expression during a destroy + // For a destroy-time provisioner forEach is intentionally nil here, + // which EvalDataForInstanceKey responds to by not populating EachValue + // in its result. That's okay because each.value is prohibited for + // destroy-time provisioners. if n.When != configs.ProvisionerWhenDestroy { m, forEachDiags := evaluateResourceForEachExpression(n.ResourceConfig.ForEach, ctx) diags = diags.Append(forEachDiags) diff --git a/terraform/evaluate.go b/terraform/evaluate.go index 1ce77a64f..96a981070 100644 --- a/terraform/evaluate.go +++ b/terraform/evaluate.go @@ -104,6 +104,11 @@ type InstanceKeyEvalData = instances.RepetitionData // EvalDataForInstanceKey constructs a suitable InstanceKeyEvalData for // evaluating in a context that has the given instance key. +// +// The forEachMap argument can be nil when preparing for evaluation +// in a context where each.value is prohibited, such as a destroy-time +// provisioner. In that case, the returned EachValue will always be +// cty.NilVal. func EvalDataForInstanceKey(key addrs.InstanceKey, forEachMap map[string]cty.Value) InstanceKeyEvalData { var evalData InstanceKeyEvalData if key == nil {