show value is ephemeral in terraform test

pull/35862/head
Daniel Schmidt 2 years ago
parent b9f273639d
commit b701e152e5
No known key found for this signature in database
GPG Key ID: 377C3A4D62FBBBE2

@ -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": {

@ -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 {

@ -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)
}

@ -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),
})
}

@ -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),
})
}

Loading…
Cancel
Save