@@ -267,6 +267,7 @@ func optionalStringEnum[T ~string](block *terraform.Block, key string, def T, va
267
267
func requiredString (block * terraform.Block , key string ) (string , * hcl.Diagnostic ) {
268
268
tyAttr := block .GetAttribute (key )
269
269
tyVal := tyAttr .Value ()
270
+
270
271
if tyVal .Type () != cty .String {
271
272
typeName := "<nil>"
272
273
if ! tyVal .Type ().Equals (cty .NilType ) {
@@ -297,8 +298,24 @@ func requiredString(block *terraform.Block, key string) (string, *hcl.Diagnostic
297
298
return "" , diag
298
299
}
299
300
300
- // nolint:gocritic // string type asserted
301
- return tyVal .AsString (), nil
301
+ tyValStr , ok := hclext .AsString (tyVal )
302
+ if ! ok {
303
+ // Either the val is unknown or null
304
+ diag := & hcl.Diagnostic {
305
+ Severity : hcl .DiagError ,
306
+ Summary : fmt .Sprintf ("Invalid %q attribute for block %s" , key , block .Label ()),
307
+ Detail : "Expected a string, got an unknown or null value" ,
308
+ EvalContext : block .Context ().Inner (),
309
+ }
310
+
311
+ if tyAttr .IsNotNil () {
312
+ diag .Subject = & (tyAttr .HCLAttribute ().Range )
313
+ // diag.Context = &(block.HCLBlock().DefRange)
314
+ diag .Expression = tyAttr .HCLAttribute ().Expr
315
+ }
316
+ return "" , diag
317
+ }
318
+ return tyValStr , nil
302
319
}
303
320
304
321
func optionalBoolean (block * terraform.Block , key string ) bool {
0 commit comments