@@ -27,6 +27,7 @@ type shareDataSource struct {
2727}
2828
2929type shareDataSourceModel struct {
30+ ID types.String `tfsdk:"id"`
3031 Shares []shareModel `tfsdk:"shares"`
3132}
3233
@@ -70,42 +71,45 @@ func (d *shareDataSource) Metadata(_ context.Context, req datasource.MetadataReq
7071func (d * shareDataSource ) Schema (_ context.Context , _ datasource.SchemaRequest , resp * datasource.SchemaResponse ) {
7172 resp .Schema = schema.Schema {
7273 Attributes : map [string ]schema.Attribute {
73- "share" : schema.ListNestedAttribute {
74+ "id" : schema.StringAttribute {
75+ Optional : true ,
76+ },
77+ "shares" : schema.ListNestedAttribute {
7478 Computed : true ,
7579 NestedObject : schema.NestedAttributeObject {
7680 Attributes : map [string ]schema.Attribute {
7781 "id" : schema.StringAttribute {
78- Required : true ,
82+ Computed : true ,
7983 },
8084 "role_id" : schema.StringAttribute {
81- Optional : true ,
85+ Computed : true ,
8286 },
8387 "name" : schema.StringAttribute {
84- Optional : true ,
88+ Computed : true ,
8589 },
8690 "username" : schema.StringAttribute {
87- Optional : true ,
91+ Computed : true ,
8892 },
8993 "active" : schema.BoolAttribute {
90- Optional : true ,
94+ Computed : true ,
9195 },
9296 "deleted" : schema.BoolAttribute {
93- Optional : true ,
97+ Computed : true ,
9498 },
9599 "created" : schema.StringAttribute {
96- Required : true ,
100+ Computed : true ,
97101 },
98102 "modified" : schema.StringAttribute {
99- Required : true ,
103+ Computed : true ,
100104 },
101105 "created_by" : schema.StringAttribute {
102- Required : true ,
106+ Computed : true ,
103107 },
104108 "modified_by" : schema.StringAttribute {
105- Optional : true ,
109+ Computed : true ,
106110 },
107111 "folder_parent_id" : schema.StringAttribute {
108- Optional : true ,
112+ Computed : true ,
109113 },
110114 },
111115 },
@@ -117,11 +121,14 @@ func (d *shareDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
117121// Read refreshes the Terraform state with the latest data.
118122func (d * shareDataSource ) Read (ctx context.Context , req datasource.ReadRequest , resp * datasource.ReadResponse ) {
119123 var state shareDataSourceModel
120- var data shareModel
121- diag := req .Config .Get (ctx , & data )
122- resp .Diagnostics .Append (diag ... )
123124
124- shares , err := d .client .Client .SearchAROs (d .client .Context , api.SearchAROsOptions {FilterSearch : data .ID .String ()})
125+ resp .Diagnostics .Append (req .Config .Get (ctx , & state )... )
126+
127+ var opts api.SearchAROsOptions
128+ if state .ID .String () != "" {
129+ opts = api.SearchAROsOptions {FilterSearch : state .ID .String ()}
130+ }
131+ shares , err := d .client .Client .SearchAROs (d .client .Context , opts )
125132 if err != nil {
126133 resp .Diagnostics .AddError (
127134 "Unable to Read shares" , "" ,
@@ -130,6 +137,7 @@ func (d *shareDataSource) Read(ctx context.Context, req datasource.ReadRequest,
130137 }
131138
132139 // Map response body to model
140+ state .Shares = make ([]shareModel , 0 )
133141 for _ , share := range shares {
134142 shareState := shareModel {
135143 ID : types .StringValue (share .User .ID ),
0 commit comments