@@ -267,6 +267,7 @@ func optionalStringEnum[T ~string](block *terraform.Block, key string, def T, va
267267func requiredString (block * terraform.Block , key string ) (string , * hcl.Diagnostic ) {
268268 tyAttr := block .GetAttribute (key )
269269 tyVal := tyAttr .Value ()
270+
270271 if tyVal .Type () != cty .String {
271272 typeName := "<nil>"
272273 if ! tyVal .Type ().Equals (cty .NilType ) {
@@ -297,8 +298,24 @@ func requiredString(block *terraform.Block, key string) (string, *hcl.Diagnostic
297298 return "" , diag
298299 }
299300
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
302319}
303320
304321func optionalBoolean (block * terraform.Block , key string ) bool {
0 commit comments