diff --git a/internal/command/test_test.go b/internal/command/test_test.go index 1fe5405382..9f0e6c0130 100644 --- a/internal/command/test_test.go +++ b/internal/command/test_test.go @@ -267,7 +267,7 @@ func TestTest_Runs(t *testing.T) { }, "ephemeral_input_with_error": { expectedOut: []string{"Error message refers to ephemeral values", "1 passed, 1 failed."}, - expectedErr: []string{"Test assertion failed"}, + expectedErr: []string{"Test assertion failed", "has an ephemeral value"}, code: 1, }, "ephemeral_resource": { diff --git a/internal/moduletest/eval_context.go b/internal/moduletest/eval_context.go index 672f1c4ee5..3822d2b119 100644 --- a/internal/moduletest/eval_context.go +++ b/internal/moduletest/eval_context.go @@ -179,6 +179,8 @@ func (ec *EvalContext) Evaluate() (Status, cty.Value, tfdiags.Diagnostics) { Subject: rule.Condition.Range().Ptr(), Expression: rule.Condition, EvalContext: hclCtx, + // Make the ephemerality visible + Extra: terraform.DiagnosticCausedByEphemeral(true), }) continue } else { diff --git a/internal/terraform/diagnostics.go b/internal/terraform/diagnostics.go index 9481363ae6..ac1ff905fe 100644 --- a/internal/terraform/diagnostics.go +++ b/internal/terraform/diagnostics.go @@ -27,20 +27,20 @@ func (e diagnosticCausedByUnknown) DiagnosticCausedByUnknown() bool { return bool(e) } -// diagnosticCausedByEphemeral is an implementation of +// DiagnosticCausedByEphemeral is an implementation of // tfdiags.DiagnosticExtraBecauseEphemeral which we can use in the "Extra" field // of a diagnostic to indicate that the problem was caused by ephemeral values // being involved in an expression evaluation. // -// When using this, set the Extra to diagnosticCausedByEphemeral(true) and also +// When using this, set the Extra to DiagnosticCausedByEphemeral(true) and also // populate the EvalContext and Expression fields of the diagnostic so that // the diagnostic renderer can use all of that information together to assist // the user in understanding what was ephemeral. -type diagnosticCausedByEphemeral bool +type DiagnosticCausedByEphemeral bool -var _ tfdiags.DiagnosticExtraBecauseEphemeral = diagnosticCausedByEphemeral(true) +var _ tfdiags.DiagnosticExtraBecauseEphemeral = DiagnosticCausedByEphemeral(true) -func (e diagnosticCausedByEphemeral) DiagnosticCausedByEphemeral() bool { +func (e DiagnosticCausedByEphemeral) DiagnosticCausedByEphemeral() bool { return bool(e) } diff --git a/internal/terraform/eval_count.go b/internal/terraform/eval_count.go index bd86f435cb..aea7f92c17 100644 --- a/internal/terraform/eval_count.go +++ b/internal/terraform/eval_count.go @@ -58,7 +58,7 @@ func evaluateCountExpression(expr hcl.Expression, ctx EvalContext, allowUnknown Summary: "Invalid count argument", Detail: `The given "count" value is derived from an ephemeral value, which means that Terraform cannot persist it between plan/apply rounds. Use only non-ephemeral values here.`, Subject: expr.Range().Ptr(), - Extra: diagnosticCausedByEphemeral(true), + Extra: DiagnosticCausedByEphemeral(true), }) return -1, diags } @@ -98,7 +98,7 @@ func evaluateCountExpressionValue(expr hcl.Expression, ctx EvalContext) (cty.Val // we can't easily do that right now because the hcl.EvalContext // (which is not the same as the ctx we have in scope here) is // hidden away inside ctx.EvaluateExpr. - Extra: diagnosticCausedByEphemeral(true), + Extra: DiagnosticCausedByEphemeral(true), }) } diff --git a/internal/terraform/eval_for_each.go b/internal/terraform/eval_for_each.go index 8742f266a6..b71cb824c5 100644 --- a/internal/terraform/eval_for_each.go +++ b/internal/terraform/eval_for_each.go @@ -271,7 +271,7 @@ func (ev *forEachEvaluator) ensureNotEphemeral(forEachVal cty.Value) tfdiags.Dia Subject: ev.expr.Range().Ptr(), Expression: ev.expr, EvalContext: ev.hclCtx, - Extra: diagnosticCausedByEphemeral(true), + Extra: DiagnosticCausedByEphemeral(true), }) }