@@ -278,6 +278,34 @@ func (data *RoleData) toAPIModel(ctx context.Context) (*models.Role, diag.Diagno
278278func (data * RoleData ) fromAPIModel (ctx context.Context , role * models.Role ) diag.Diagnostics {
279279 var diags diag.Diagnostics
280280
281+ // Define attribute type maps
282+ applicationAttrTypes := map [string ]attr.Type {
283+ "application" : types .StringType ,
284+ "privileges" : types.SetType {ElemType : types .StringType },
285+ "resources" : types.SetType {ElemType : types .StringType },
286+ }
287+
288+ fieldSecurityAttrTypes := map [string ]attr.Type {
289+ "grant" : types.SetType {ElemType : types .StringType },
290+ "except" : types.SetType {ElemType : types .StringType },
291+ }
292+
293+ indexPermsAttrTypes := map [string ]attr.Type {
294+ "field_security" : types.ListType {ElemType : types.ObjectType {AttrTypes : fieldSecurityAttrTypes }},
295+ "names" : types.SetType {ElemType : types .StringType },
296+ "privileges" : types.SetType {ElemType : types .StringType },
297+ "query" : jsontypes.NormalizedType {},
298+ "allow_restricted_indices" : types .BoolType ,
299+ }
300+
301+ remoteIndexPermsAttrTypes := map [string ]attr.Type {
302+ "clusters" : types.SetType {ElemType : types .StringType },
303+ "field_security" : types.ListType {ElemType : types.ObjectType {AttrTypes : fieldSecurityAttrTypes }},
304+ "query" : jsontypes.NormalizedType {},
305+ "names" : types.SetType {ElemType : types .StringType },
306+ "privileges" : types.SetType {ElemType : types .StringType },
307+ }
308+
281309 data .Name = types .StringValue (role .Name )
282310
283311 // Description
@@ -299,7 +327,7 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
299327 return diags
300328 }
301329
302- appObj , d := types .ObjectValue (getApplicationAttrTypes () , map [string ]attr.Value {
330+ appObj , d := types .ObjectValue (applicationAttrTypes , map [string ]attr.Value {
303331 "application" : types .StringValue (app .Name ),
304332 "privileges" : privSet ,
305333 "resources" : resSet ,
@@ -312,14 +340,14 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
312340 appElements [i ] = appObj
313341 }
314342
315- appSet , d := types .SetValue (types.ObjectType {AttrTypes : getApplicationAttrTypes () }, appElements )
343+ appSet , d := types .SetValue (types.ObjectType {AttrTypes : applicationAttrTypes }, appElements )
316344 diags .Append (d ... )
317345 if diags .HasError () {
318346 return diags
319347 }
320348 data .Applications = appSet
321349 } else {
322- data .Applications = types .SetNull (types.ObjectType {AttrTypes : getApplicationAttrTypes () })
350+ data .Applications = types .SetNull (types.ObjectType {AttrTypes : applicationAttrTypes })
323351 }
324352
325353 // Cluster
@@ -369,7 +397,12 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
369397 queryVal = jsontypes .NewNormalizedNull ()
370398 }
371399
372- allowRestrictedVal := types .BoolPointerValue (index .AllowRestrictedIndices )
400+ var allowRestrictedVal types.Bool
401+ if index .AllowRestrictedIndices != nil {
402+ allowRestrictedVal = types .BoolValue (* index .AllowRestrictedIndices )
403+ } else {
404+ allowRestrictedVal = types .BoolNull ()
405+ }
373406
374407 var fieldSecList types.List
375408 if index .FieldSecurity != nil {
@@ -385,7 +418,7 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
385418 return diags
386419 }
387420
388- fieldSecObj , d := types .ObjectValue (getFieldSecurityAttrTypes () , map [string ]attr.Value {
421+ fieldSecObj , d := types .ObjectValue (fieldSecurityAttrTypes , map [string ]attr.Value {
389422 "grant" : grantSet ,
390423 "except" : exceptSet ,
391424 })
@@ -394,16 +427,16 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
394427 return diags
395428 }
396429
397- fieldSecList , d = types .ListValue (types.ObjectType {AttrTypes : getFieldSecurityAttrTypes () }, []attr.Value {fieldSecObj })
430+ fieldSecList , d = types .ListValue (types.ObjectType {AttrTypes : fieldSecurityAttrTypes }, []attr.Value {fieldSecObj })
398431 diags .Append (d ... )
399432 if diags .HasError () {
400433 return diags
401434 }
402435 } else {
403- fieldSecList = types .ListNull (types.ObjectType {AttrTypes : getFieldSecurityAttrTypes () })
436+ fieldSecList = types .ListNull (types.ObjectType {AttrTypes : fieldSecurityAttrTypes })
404437 }
405438
406- indexObj , d := types .ObjectValue (getIndexPermsAttrTypes () , map [string ]attr.Value {
439+ indexObj , d := types .ObjectValue (indexPermsAttrTypes , map [string ]attr.Value {
407440 "field_security" : fieldSecList ,
408441 "names" : namesSet ,
409442 "privileges" : privSet ,
@@ -418,14 +451,14 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
418451 indicesElements [i ] = indexObj
419452 }
420453
421- indicesSet , d := types .SetValue (types.ObjectType {AttrTypes : getIndexPermsAttrTypes () }, indicesElements )
454+ indicesSet , d := types .SetValue (types.ObjectType {AttrTypes : indexPermsAttrTypes }, indicesElements )
422455 diags .Append (d ... )
423456 if diags .HasError () {
424457 return diags
425458 }
426459 data .Indices = indicesSet
427460 } else {
428- data .Indices = types .SetNull (types.ObjectType {AttrTypes : getIndexPermsAttrTypes () })
461+ data .Indices = types .SetNull (types.ObjectType {AttrTypes : indexPermsAttrTypes })
429462 }
430463
431464 // Remote Indices
@@ -471,7 +504,7 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
471504 return diags
472505 }
473506
474- fieldSecObj , d := types .ObjectValue (getFieldSecurityAttrTypes () , map [string ]attr.Value {
507+ fieldSecObj , d := types .ObjectValue (fieldSecurityAttrTypes , map [string ]attr.Value {
475508 "grant" : grantSet ,
476509 "except" : exceptSet ,
477510 })
@@ -480,16 +513,16 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
480513 return diags
481514 }
482515
483- fieldSecList , d = types .ListValue (types.ObjectType {AttrTypes : getFieldSecurityAttrTypes () }, []attr.Value {fieldSecObj })
516+ fieldSecList , d = types .ListValue (types.ObjectType {AttrTypes : fieldSecurityAttrTypes }, []attr.Value {fieldSecObj })
484517 diags .Append (d ... )
485518 if diags .HasError () {
486519 return diags
487520 }
488521 } else {
489- fieldSecList = types .ListNull (types.ObjectType {AttrTypes : getFieldSecurityAttrTypes () })
522+ fieldSecList = types .ListNull (types.ObjectType {AttrTypes : fieldSecurityAttrTypes })
490523 }
491524
492- remoteIndexObj , d := types .ObjectValue (getRemoteIndexPermsAttrTypes () , map [string ]attr.Value {
525+ remoteIndexObj , d := types .ObjectValue (remoteIndexPermsAttrTypes , map [string ]attr.Value {
493526 "clusters" : clustersSet ,
494527 "field_security" : fieldSecList ,
495528 "query" : queryVal ,
@@ -504,14 +537,14 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
504537 remoteIndicesElements [i ] = remoteIndexObj
505538 }
506539
507- remoteIndicesSet , d := types .SetValue (types.ObjectType {AttrTypes : getRemoteIndexPermsAttrTypes () }, remoteIndicesElements )
540+ remoteIndicesSet , d := types .SetValue (types.ObjectType {AttrTypes : remoteIndexPermsAttrTypes }, remoteIndicesElements )
508541 diags .Append (d ... )
509542 if diags .HasError () {
510543 return diags
511544 }
512545 data .RemoteIndices = remoteIndicesSet
513546 } else {
514- data .RemoteIndices = types .SetNull (types.ObjectType {AttrTypes : getRemoteIndexPermsAttrTypes () })
547+ data .RemoteIndices = types .SetNull (types.ObjectType {AttrTypes : remoteIndexPermsAttrTypes })
515548 }
516549
517550 // Metadata
0 commit comments