diff --git a/terraform/eval_count.go b/terraform/eval_count.go index 99ddeafee..b09c72e66 100644 --- a/terraform/eval_count.go +++ b/terraform/eval_count.go @@ -12,18 +12,13 @@ import ( ) // evaluateCountExpression is our standard mechanism for interpreting an -// expression given for a "count" argument on a resource. This should be called -// from the DynamicExpand of a node representing a resource in order to -// determine the final count value. +// expression given for a "count" argument on a resource or a module. This +// should be called during expansion in order to determine the final count +// value. // -// If the result is zero or positive and no error diagnostics are returned, then -// the result is the literal count value to use. -// -// If the result is -1, this indicates that the given expression is nil and so -// the "count" behavior should not be enabled for this resource at all. -// -// If error diagnostics are returned then the result is always the meaningless -// placeholder value -1. +// evaluateCountExpression differs from evaluateCountExpressionValue by +// returning an error if the count value is not known, and converting the +// cty.Value to an integer. func evaluateCountExpression(expr hcl.Expression, ctx EvalContext) (int, tfdiags.Diagnostics) { countVal, diags := evaluateCountExpressionValue(expr, ctx) if !countVal.IsKnown() { diff --git a/terraform/eval_for_each.go b/terraform/eval_for_each.go index 978e034d9..02ec4815b 100644 --- a/terraform/eval_for_each.go +++ b/terraform/eval_for_each.go @@ -8,11 +8,14 @@ import ( "github.com/zclconf/go-cty/cty" ) -// evaluateForEachExpression interprets a "for_each" argument on a resource. +// evaluateForEachExpression is our standard mechanism for interpreting an +// expression given for a "for_each" argument on a resource or a module. This +// should be called during expansion in order to determine the final keys and +// values. // -// Returns a cty.Value map, and diagnostics if necessary. It will return nil if -// the expression is nil, and is used to distinguish between an unset for_each and an -// empty map +// evaluateForEachExpression differs from evaluateForEachExpressionValue by +// returning an error if the count value is not known, and converting the +// cty.Value to a map[string]cty.Value for compatibility with other calls. func evaluateForEachExpression(expr hcl.Expression, ctx EvalContext) (forEach map[string]cty.Value, diags tfdiags.Diagnostics) { forEachVal, diags := evaluateForEachExpressionValue(expr, ctx) if !forEachVal.IsKnown() {