You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Custom variable validations specified using JSON syntax would always
parse error messages as string literals, even if they included template
expressions. We need to be as backwards compatible with this behaviour
as possible, which results in this complex fallback logic. More detail
about this in the extensive code comments.
// Decoding succeeded, meaning that this is a JSON syntax
242
+
// string value. We rewrap that as a cty value to allow later
243
+
// decoding to succeed.
244
+
errorValue=cty.StringVal(errorString)
245
+
246
+
// This warning diagnostic explains this odd behaviour, while
247
+
// giving us an escape hatch to change this to a hard failure
248
+
// in some future Terraform 1.x version.
249
+
errorDiags= hcl.Diagnostics{
250
+
&hcl.Diagnostic{
251
+
Severity: hcl.DiagWarning,
252
+
Summary: "Validation error message expression is invalid",
253
+
Detail: fmt.Sprintf("The error message provided could not be evaluated as an expression, so Terraform is interpreting it as a string literal.\n\nIn future versions of Terraform, this will be considered an error. Please file a GitHub issue if this would break your workflow.\n\n%s", errorDiags.Error()),
254
+
Subject: validation.ErrorMessage.Range().Ptr(),
255
+
Context: validation.DeclRange.Ptr(),
256
+
Expression: validation.ErrorMessage,
257
+
EvalContext: hclCtx,
258
+
},
259
+
}
260
+
}
261
+
262
+
// We want to either report the original diagnostics if the
263
+
// fallback failed, or the warning generated above if it succeeded.
0 commit comments