File tree 2 files changed +35
-1
lines changed
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) {
250
250
}
251
251
252
252
func (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
254
268
}
255
269
256
270
func (e * TemplateWrapExpr ) Range () hcl.Range {
Original file line number Diff line number Diff line change @@ -403,6 +403,26 @@ trim`,
403
403
cty .UnknownVal (cty .String ).Mark ("sensitive" ).Refine ().NotNull ().StringPrefixFull ("test_" ).NewValue (),
404
404
0 ,
405
405
},
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
+ },
406
426
}
407
427
408
428
for _ , test := range tests {
You can’t perform that action at this time.
0 commit comments