// 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.
//
// 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.
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.

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.
// 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 . // // 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() {
		diags = diags.Append(&hcl.Diagnostic{
			Severity: hcl.DiagError,
			Summary:  "Invalid for_each argument",
			Detail:   `The "for_each" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only the resources that the for_each depends on.`,
			Subject:  expr.Range().Ptr(),
		})
	}
	if forEachVal.IsNull() || !forEachVal.IsKnown() || markSafeLengthInt(forEachVal) == 0 {
		return map[string]cty.Value{}, diags
	}
	return forEachVal.AsValueMap(), diags
}
func evaluateForEachExpression ( expr hcl . Expression , ctx EvalContext ) ( forEach map [ string ] cty . Value , diags tfdiags . Diagnostics ) { forEachVal , diags := evaluateForEachExpressionValue ( expr , ctx ) if ! forEachVal . IsKnown ( ) { diags = diags . Append ( & hcl . Diagnostic { Severity : hcl . DiagError , Summary : " " , Detail : `The "for_each" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only the resources that the for_each depends on.` , Subject : expr . Range ( ) . Ptr ( ) , } ) } if forEachVal . IsNull ( ) || ! forEachVal . IsKnown ( ) || markSafeLengthInt ( forEachVal ) == 0 { return map [ string ] cty . Value { } , diags } return forEachVal . AsValueMap ( ) , diags }
evaluateForEachExpression is our standard mechanism for interpreting an
expression given for a "for_each" argument on a resource or a module.
evaluateForEachExpression is our standard mechanism for interpreting an expression given for a " for_each " argument on a resource or a module .
// Attach a diag as we do with count, with the same downsides // we check length, because an empty set return a nil map