@@ -13,35 +13,6 @@ import (
1313 "github.com/hashicorp/terraform-plugin-framework/types"
1414)
1515
16- var (
17- applicationAttrTypes = map [string ]attr.Type {
18- "application" : types .StringType ,
19- "privileges" : types.SetType {ElemType : types .StringType },
20- "resources" : types.SetType {ElemType : types .StringType },
21- }
22-
23- fieldSecurityAttrTypes = map [string ]attr.Type {
24- "grant" : types.SetType {ElemType : types .StringType },
25- "except" : types.SetType {ElemType : types .StringType },
26- }
27-
28- indexPermsAttrTypes = map [string ]attr.Type {
29- "field_security" : types.ListType {ElemType : types.ObjectType {AttrTypes : fieldSecurityAttrTypes }},
30- "names" : types.SetType {ElemType : types .StringType },
31- "privileges" : types.SetType {ElemType : types .StringType },
32- "query" : jsontypes.NormalizedType {},
33- "allow_restricted_indices" : types .BoolType ,
34- }
35-
36- remoteIndexPermsAttrTypes = map [string ]attr.Type {
37- "clusters" : types.SetType {ElemType : types .StringType },
38- "field_security" : types.ListType {ElemType : types.ObjectType {AttrTypes : fieldSecurityAttrTypes }},
39- "query" : jsontypes.NormalizedType {},
40- "names" : types.SetType {ElemType : types .StringType },
41- "privileges" : types.SetType {ElemType : types .StringType },
42- }
43- )
44-
4516type RoleData struct {
4617 Id types.String `tfsdk:"id"`
4718 ElasticsearchConnection types.List `tfsdk:"elasticsearch_connection"`
@@ -329,7 +300,7 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
329300 return diags
330301 }
331302
332- appObj , d := types .ObjectValue (applicationAttrTypes , map [string ]attr.Value {
303+ appObj , d := types .ObjectValue (getApplicationAttrTypes () , map [string ]attr.Value {
333304 "application" : types .StringValue (app .Name ),
334305 "privileges" : privSet ,
335306 "resources" : resSet ,
@@ -342,14 +313,14 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
342313 appElements [i ] = appObj
343314 }
344315
345- appSet , d := types .SetValue (types.ObjectType {AttrTypes : applicationAttrTypes }, appElements )
316+ appSet , d := types .SetValue (types.ObjectType {AttrTypes : getApplicationAttrTypes () }, appElements )
346317 diags .Append (d ... )
347318 if diags .HasError () {
348319 return diags
349320 }
350321 data .Applications = appSet
351322 } else {
352- data .Applications = types .SetNull (types.ObjectType {AttrTypes : applicationAttrTypes })
323+ data .Applications = types .SetNull (types.ObjectType {AttrTypes : getApplicationAttrTypes () })
353324 }
354325
355326 // Cluster
@@ -420,7 +391,7 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
420391 return diags
421392 }
422393
423- fieldSecObj , d := types .ObjectValue (fieldSecurityAttrTypes , map [string ]attr.Value {
394+ fieldSecObj , d := types .ObjectValue (getFieldSecurityAttrTypes () , map [string ]attr.Value {
424395 "grant" : grantSet ,
425396 "except" : exceptSet ,
426397 })
@@ -429,16 +400,16 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
429400 return diags
430401 }
431402
432- fieldSecList , d = types .ListValue (types.ObjectType {AttrTypes : fieldSecurityAttrTypes }, []attr.Value {fieldSecObj })
403+ fieldSecList , d = types .ListValue (types.ObjectType {AttrTypes : getFieldSecurityAttrTypes () }, []attr.Value {fieldSecObj })
433404 diags .Append (d ... )
434405 if diags .HasError () {
435406 return diags
436407 }
437408 } else {
438- fieldSecList = types .ListNull (types.ObjectType {AttrTypes : fieldSecurityAttrTypes })
409+ fieldSecList = types .ListNull (types.ObjectType {AttrTypes : getFieldSecurityAttrTypes () })
439410 }
440411
441- indexObj , d := types .ObjectValue (indexPermsAttrTypes , map [string ]attr.Value {
412+ indexObj , d := types .ObjectValue (getIndexPermsAttrTypes () , map [string ]attr.Value {
442413 "field_security" : fieldSecList ,
443414 "names" : namesSet ,
444415 "privileges" : privSet ,
@@ -453,14 +424,14 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
453424 indicesElements [i ] = indexObj
454425 }
455426
456- indicesSet , d := types .SetValue (types.ObjectType {AttrTypes : indexPermsAttrTypes }, indicesElements )
427+ indicesSet , d := types .SetValue (types.ObjectType {AttrTypes : getIndexPermsAttrTypes () }, indicesElements )
457428 diags .Append (d ... )
458429 if diags .HasError () {
459430 return diags
460431 }
461432 data .Indices = indicesSet
462433 } else {
463- data .Indices = types .SetNull (types.ObjectType {AttrTypes : indexPermsAttrTypes })
434+ data .Indices = types .SetNull (types.ObjectType {AttrTypes : getIndexPermsAttrTypes () })
464435 }
465436
466437 // Remote Indices
@@ -494,19 +465,19 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
494465
495466 var fieldSecList types.List
496467 if remoteIndex .FieldSecurity != nil {
497- grantSet , d := types .SetValueFrom (ctx , types .StringType , remoteIndex .FieldSecurity .Grant )
468+ grantSet , d := types .SetValueFrom (ctx , types .StringType , utils . NonNilSlice ( remoteIndex .FieldSecurity .Grant ) )
498469 diags .Append (d ... )
499470 if diags .HasError () {
500471 return diags
501472 }
502473
503- exceptSet , d := types .SetValueFrom (ctx , types .StringType , remoteIndex .FieldSecurity .Except )
474+ exceptSet , d := types .SetValueFrom (ctx , types .StringType , utils . NonNilSlice ( remoteIndex .FieldSecurity .Except ) )
504475 diags .Append (d ... )
505476 if diags .HasError () {
506477 return diags
507478 }
508479
509- fieldSecObj , d := types .ObjectValue (fieldSecurityAttrTypes , map [string ]attr.Value {
480+ fieldSecObj , d := types .ObjectValue (getRemoteFieldSecurityAttrTypes () , map [string ]attr.Value {
510481 "grant" : grantSet ,
511482 "except" : exceptSet ,
512483 })
@@ -515,16 +486,16 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
515486 return diags
516487 }
517488
518- fieldSecList , d = types .ListValue (types.ObjectType {AttrTypes : fieldSecurityAttrTypes }, []attr.Value {fieldSecObj })
489+ fieldSecList , d = types .ListValue (types.ObjectType {AttrTypes : getRemoteFieldSecurityAttrTypes () }, []attr.Value {fieldSecObj })
519490 diags .Append (d ... )
520491 if diags .HasError () {
521492 return diags
522493 }
523494 } else {
524- fieldSecList = types .ListNull (types.ObjectType {AttrTypes : fieldSecurityAttrTypes })
495+ fieldSecList = types .ListNull (types.ObjectType {AttrTypes : getRemoteFieldSecurityAttrTypes () })
525496 }
526497
527- remoteIndexObj , d := types .ObjectValue (remoteIndexPermsAttrTypes , map [string ]attr.Value {
498+ remoteIndexObj , d := types .ObjectValue (getRemoteIndexPermsAttrTypes () , map [string ]attr.Value {
528499 "clusters" : clustersSet ,
529500 "field_security" : fieldSecList ,
530501 "query" : queryVal ,
@@ -539,14 +510,14 @@ func (data *RoleData) fromAPIModel(ctx context.Context, role *models.Role) diag.
539510 remoteIndicesElements [i ] = remoteIndexObj
540511 }
541512
542- remoteIndicesSet , d := types .SetValue (types.ObjectType {AttrTypes : remoteIndexPermsAttrTypes }, remoteIndicesElements )
513+ remoteIndicesSet , d := types .SetValue (types.ObjectType {AttrTypes : getRemoteIndexPermsAttrTypes () }, remoteIndicesElements )
543514 diags .Append (d ... )
544515 if diags .HasError () {
545516 return diags
546517 }
547518 data .RemoteIndices = remoteIndicesSet
548519 } else {
549- data .RemoteIndices = types .SetNull (types.ObjectType {AttrTypes : remoteIndexPermsAttrTypes })
520+ data .RemoteIndices = types .SetNull (types.ObjectType {AttrTypes : getRemoteIndexPermsAttrTypes () })
550521 }
551522
552523 // Metadata
0 commit comments