File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -250,7 +250,21 @@ func (e *TemplateWrapExpr) walkChildNodes(w internalWalkFunc) {
250250}
251251
252252func (e * TemplateWrapExpr ) Value (ctx * hcl.EvalContext ) (cty.Value , hcl.Diagnostics ) {
253- return e .Wrapped .Value (ctx )
253+ val , diags := e .Wrapped .Value (ctx )
254+
255+ // If the single interpolation result is null, we need to return the same
256+ // error as we would for a TemplateExpr with a null part.
257+ if val .IsNull () {
258+ diags = append (diags , & hcl.Diagnostic {
259+ Severity : hcl .DiagError ,
260+ Summary : "Invalid template interpolation value" ,
261+ Detail : "The expression result is null. Cannot include a null value in a string template." ,
262+ Subject : e .Range ().Ptr (),
263+ Expression : e .Wrapped ,
264+ EvalContext : ctx ,
265+ })
266+ }
267+ return val , diags
254268}
255269
256270func (e * TemplateWrapExpr ) Range () hcl.Range {
Original file line number Diff line number Diff line change @@ -403,6 +403,26 @@ trim`,
403403 cty .UnknownVal (cty .String ).Mark ("sensitive" ).Refine ().NotNull ().StringPrefixFull ("test_" ).NewValue (),
404404 0 ,
405405 },
406+ { // template with a single wrapped expr that is null
407+ `${hello}` ,
408+ & hcl.EvalContext {
409+ Variables : map [string ]cty.Value {
410+ "hello" : cty .NullVal (cty .String ),
411+ },
412+ },
413+ cty .NullVal (cty .String ),
414+ 1 , // error about null value
415+ },
416+ {
417+ `foo ${hello}` ,
418+ & hcl.EvalContext {
419+ Variables : map [string ]cty.Value {
420+ "hello" : cty .NullVal (cty .String ),
421+ },
422+ },
423+ cty .StringVal ("foo " ),
424+ 1 , // error about null value
425+ },
406426 }
407427
408428 for _ , test := range tests {
You can’t perform that action at this time.
0 commit comments