@@ -32,7 +32,7 @@ func NewGroupResource() resource.Resource {
32
32
33
33
// GroupResource defines the resource implementation.
34
34
type GroupResource struct {
35
- data * CoderdProviderData
35
+ * CoderdProviderData
36
36
}
37
37
38
38
// GroupResourceModel describes the resource data model.
@@ -137,34 +137,26 @@ func (r *GroupResource) Configure(ctx context.Context, req resource.ConfigureReq
137
137
return
138
138
}
139
139
140
- r .data = data
140
+ r .CoderdProviderData = data
141
141
}
142
142
143
143
func (r * GroupResource ) Create (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
144
- var data GroupResourceModel
145
-
146
144
// Read Terraform plan data into the model
145
+ var data GroupResourceModel
147
146
resp .Diagnostics .Append (req .Plan .Get (ctx , & data )... )
148
-
149
147
if resp .Diagnostics .HasError () {
150
148
return
151
149
}
152
150
153
- resp .Diagnostics .Append (CheckGroupEntitlements (ctx , r .data . Features )... )
151
+ resp .Diagnostics .Append (CheckGroupEntitlements (ctx , r .Features )... )
154
152
if resp .Diagnostics .HasError () {
155
153
return
156
154
}
157
155
158
- client := r .data .Client
159
-
160
- if data .OrganizationID .IsUnknown () {
161
- data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
162
- }
163
-
164
156
orgID := data .OrganizationID .ValueUUID ()
165
157
166
158
tflog .Info (ctx , "creating group" )
167
- group , err := client .CreateGroup (ctx , orgID , codersdk.CreateGroupRequest {
159
+ group , err := r . Client .CreateGroup (ctx , orgID , codersdk.CreateGroupRequest {
168
160
Name : data .Name .ValueString (),
169
161
DisplayName : data .DisplayName .ValueString (),
170
162
AvatarURL : data .AvatarURL .ValueString (),
@@ -188,7 +180,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
188
180
if resp .Diagnostics .HasError () {
189
181
return
190
182
}
191
- group , err = client .PatchGroup (ctx , group .ID , codersdk.PatchGroupRequest {
183
+ group , err = r . Client .PatchGroup (ctx , group .ID , codersdk.PatchGroupRequest {
192
184
AddUsers : members ,
193
185
})
194
186
if err != nil {
@@ -202,20 +194,16 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
202
194
}
203
195
204
196
func (r * GroupResource ) Read (ctx context.Context , req resource.ReadRequest , resp * resource.ReadResponse ) {
205
- var data GroupResourceModel
206
-
207
197
// Read Terraform prior state data into the model
198
+ var data GroupResourceModel
208
199
resp .Diagnostics .Append (req .State .Get (ctx , & data )... )
209
-
210
200
if resp .Diagnostics .HasError () {
211
201
return
212
202
}
213
203
214
- client := r .data .Client
215
-
216
204
groupID := data .ID .ValueUUID ()
217
205
218
- group , err := client .Group (ctx , groupID )
206
+ group , err := r . Client .Group (ctx , groupID )
219
207
if err != nil {
220
208
if isNotFound (err ) {
221
209
resp .Diagnostics .AddWarning ("Client Warning" , fmt .Sprintf ("Group with ID %s not found. Marking as deleted." , groupID .String ()))
@@ -244,22 +232,16 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp
244
232
}
245
233
246
234
func (r * GroupResource ) Update (ctx context.Context , req resource.UpdateRequest , resp * resource.UpdateResponse ) {
247
- var data GroupResourceModel
248
-
249
235
// Read Terraform plan data into the model
236
+ var data GroupResourceModel
250
237
resp .Diagnostics .Append (req .Plan .Get (ctx , & data )... )
251
-
252
238
if resp .Diagnostics .HasError () {
253
239
return
254
240
}
255
241
256
- client := r .data .Client
257
- if data .OrganizationID .IsUnknown () {
258
- data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
259
- }
260
242
groupID := data .ID .ValueUUID ()
261
243
262
- group , err := client .Group (ctx , groupID )
244
+ group , err := r . Client .Group (ctx , groupID )
263
245
if err != nil {
264
246
resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to get group, got error: %s" , err ))
265
247
return
@@ -268,9 +250,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
268
250
var remove []string
269
251
if ! data .Members .IsNull () {
270
252
var plannedMembers []UUID
271
- resp .Diagnostics .Append (
272
- data .Members .ElementsAs (ctx , & plannedMembers , false )... ,
273
- )
253
+ resp .Diagnostics .Append (data .Members .ElementsAs (ctx , & plannedMembers , false )... )
274
254
if resp .Diagnostics .HasError () {
275
255
return
276
256
}
@@ -291,7 +271,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
291
271
})
292
272
293
273
quotaAllowance := int (data .QuotaAllowance .ValueInt32 ())
294
- _ , err = client .PatchGroup (ctx , group .ID , codersdk.PatchGroupRequest {
274
+ _ , err = r . Client .PatchGroup (ctx , group .ID , codersdk.PatchGroupRequest {
295
275
AddUsers : add ,
296
276
RemoveUsers : remove ,
297
277
Name : data .Name .ValueString (),
@@ -310,22 +290,19 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
310
290
}
311
291
312
292
func (r * GroupResource ) Delete (ctx context.Context , req resource.DeleteRequest , resp * resource.DeleteResponse ) {
313
- var data GroupResourceModel
314
-
315
293
// Read Terraform prior state data into the model
294
+ var data GroupResourceModel
316
295
resp .Diagnostics .Append (req .State .Get (ctx , & data )... )
317
-
318
296
if resp .Diagnostics .HasError () {
319
297
return
320
298
}
321
299
322
- client := r .data .Client
323
300
groupID := data .ID .ValueUUID ()
324
301
325
302
tflog .Info (ctx , "deleting group" , map [string ]any {
326
303
"id" : groupID ,
327
304
})
328
- err := client .DeleteGroup (ctx , groupID )
305
+ err := r . Client .DeleteGroup (ctx , groupID )
329
306
if err != nil {
330
307
resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to delete group, got error: %s" , err ))
331
308
return
@@ -335,7 +312,6 @@ func (r *GroupResource) Delete(ctx context.Context, req resource.DeleteRequest,
335
312
336
313
func (r * GroupResource ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
337
314
var groupID uuid.UUID
338
- client := r .data .Client
339
315
idParts := strings .Split (req .ID , "/" )
340
316
if len (idParts ) == 1 {
341
317
var err error
@@ -345,12 +321,12 @@ func (r *GroupResource) ImportState(ctx context.Context, req resource.ImportStat
345
321
return
346
322
}
347
323
} else if len (idParts ) == 2 {
348
- org , err := client .OrganizationByName (ctx , idParts [0 ])
324
+ org , err := r . Client .OrganizationByName (ctx , idParts [0 ])
349
325
if err != nil {
350
326
resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Failed to get organization with name %s: %s" , idParts [0 ], err ))
351
327
return
352
328
}
353
- group , err := client .GroupByOrgAndName (ctx , org .ID , idParts [1 ])
329
+ group , err := r . Client .GroupByOrgAndName (ctx , org .ID , idParts [1 ])
354
330
if err != nil {
355
331
resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Failed to get group with name %s: %s" , idParts [1 ], err ))
356
332
return
@@ -360,7 +336,7 @@ func (r *GroupResource) ImportState(ctx context.Context, req resource.ImportStat
360
336
resp .Diagnostics .AddError ("Client Error" , "Invalid import ID format, expected a single UUID or `<organization-name>/<group-name>`" )
361
337
return
362
338
}
363
- group , err := client .Group (ctx , groupID )
339
+ group , err := r . Client .Group (ctx , groupID )
364
340
if err != nil {
365
341
resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to get imported group, got error: %s" , err ))
366
342
return
0 commit comments