@@ -32,7 +32,7 @@ func NewGroupResource() resource.Resource {
3232
3333// GroupResource defines the resource implementation.
3434type GroupResource struct {
35- data * CoderdProviderData
35+ * CoderdProviderData
3636}
3737
3838// GroupResourceModel describes the resource data model.
@@ -137,34 +137,26 @@ func (r *GroupResource) Configure(ctx context.Context, req resource.ConfigureReq
137137 return
138138 }
139139
140- r .data = data
140+ r .CoderdProviderData = data
141141}
142142
143143func (r * GroupResource ) Create (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
144- var data GroupResourceModel
145-
146144 // Read Terraform plan data into the model
145+ var data GroupResourceModel
147146 resp .Diagnostics .Append (req .Plan .Get (ctx , & data )... )
148-
149147 if resp .Diagnostics .HasError () {
150148 return
151149 }
152150
153- resp .Diagnostics .Append (CheckGroupEntitlements (ctx , r .data . Features )... )
151+ resp .Diagnostics .Append (CheckGroupEntitlements (ctx , r .Features )... )
154152 if resp .Diagnostics .HasError () {
155153 return
156154 }
157155
158- client := r .data .Client
159-
160- if data .OrganizationID .IsUnknown () {
161- data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
162- }
163-
164156 orgID := data .OrganizationID .ValueUUID ()
165157
166158 tflog .Info (ctx , "creating group" )
167- group , err := client .CreateGroup (ctx , orgID , codersdk.CreateGroupRequest {
159+ group , err := r . Client .CreateGroup (ctx , orgID , codersdk.CreateGroupRequest {
168160 Name : data .Name .ValueString (),
169161 DisplayName : data .DisplayName .ValueString (),
170162 AvatarURL : data .AvatarURL .ValueString (),
@@ -188,7 +180,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
188180 if resp .Diagnostics .HasError () {
189181 return
190182 }
191- group , err = client .PatchGroup (ctx , group .ID , codersdk.PatchGroupRequest {
183+ group , err = r . Client .PatchGroup (ctx , group .ID , codersdk.PatchGroupRequest {
192184 AddUsers : members ,
193185 })
194186 if err != nil {
@@ -202,20 +194,16 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
202194}
203195
204196func (r * GroupResource ) Read (ctx context.Context , req resource.ReadRequest , resp * resource.ReadResponse ) {
205- var data GroupResourceModel
206-
207197 // Read Terraform prior state data into the model
198+ var data GroupResourceModel
208199 resp .Diagnostics .Append (req .State .Get (ctx , & data )... )
209-
210200 if resp .Diagnostics .HasError () {
211201 return
212202 }
213203
214- client := r .data .Client
215-
216204 groupID := data .ID .ValueUUID ()
217205
218- group , err := client .Group (ctx , groupID )
206+ group , err := r . Client .Group (ctx , groupID )
219207 if err != nil {
220208 if isNotFound (err ) {
221209 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
244232}
245233
246234func (r * GroupResource ) Update (ctx context.Context , req resource.UpdateRequest , resp * resource.UpdateResponse ) {
247- var data GroupResourceModel
248-
249235 // Read Terraform plan data into the model
236+ var data GroupResourceModel
250237 resp .Diagnostics .Append (req .Plan .Get (ctx , & data )... )
251-
252238 if resp .Diagnostics .HasError () {
253239 return
254240 }
255241
256- client := r .data .Client
257- if data .OrganizationID .IsUnknown () {
258- data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
259- }
260242 groupID := data .ID .ValueUUID ()
261243
262- group , err := client .Group (ctx , groupID )
244+ group , err := r . Client .Group (ctx , groupID )
263245 if err != nil {
264246 resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to get group, got error: %s" , err ))
265247 return
@@ -268,9 +250,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
268250 var remove []string
269251 if ! data .Members .IsNull () {
270252 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 )... )
274254 if resp .Diagnostics .HasError () {
275255 return
276256 }
@@ -291,7 +271,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
291271 })
292272
293273 quotaAllowance := int (data .QuotaAllowance .ValueInt32 ())
294- _ , err = client .PatchGroup (ctx , group .ID , codersdk.PatchGroupRequest {
274+ _ , err = r . Client .PatchGroup (ctx , group .ID , codersdk.PatchGroupRequest {
295275 AddUsers : add ,
296276 RemoveUsers : remove ,
297277 Name : data .Name .ValueString (),
@@ -310,22 +290,19 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
310290}
311291
312292func (r * GroupResource ) Delete (ctx context.Context , req resource.DeleteRequest , resp * resource.DeleteResponse ) {
313- var data GroupResourceModel
314-
315293 // Read Terraform prior state data into the model
294+ var data GroupResourceModel
316295 resp .Diagnostics .Append (req .State .Get (ctx , & data )... )
317-
318296 if resp .Diagnostics .HasError () {
319297 return
320298 }
321299
322- client := r .data .Client
323300 groupID := data .ID .ValueUUID ()
324301
325302 tflog .Info (ctx , "deleting group" , map [string ]any {
326303 "id" : groupID ,
327304 })
328- err := client .DeleteGroup (ctx , groupID )
305+ err := r . Client .DeleteGroup (ctx , groupID )
329306 if err != nil {
330307 resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to delete group, got error: %s" , err ))
331308 return
@@ -335,7 +312,6 @@ func (r *GroupResource) Delete(ctx context.Context, req resource.DeleteRequest,
335312
336313func (r * GroupResource ) ImportState (ctx context.Context , req resource.ImportStateRequest , resp * resource.ImportStateResponse ) {
337314 var groupID uuid.UUID
338- client := r .data .Client
339315 idParts := strings .Split (req .ID , "/" )
340316 if len (idParts ) == 1 {
341317 var err error
@@ -345,12 +321,12 @@ func (r *GroupResource) ImportState(ctx context.Context, req resource.ImportStat
345321 return
346322 }
347323 } else if len (idParts ) == 2 {
348- org , err := client .OrganizationByName (ctx , idParts [0 ])
324+ org , err := r . Client .OrganizationByName (ctx , idParts [0 ])
349325 if err != nil {
350326 resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Failed to get organization with name %s: %s" , idParts [0 ], err ))
351327 return
352328 }
353- group , err := client .GroupByOrgAndName (ctx , org .ID , idParts [1 ])
329+ group , err := r . Client .GroupByOrgAndName (ctx , org .ID , idParts [1 ])
354330 if err != nil {
355331 resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Failed to get group with name %s: %s" , idParts [1 ], err ))
356332 return
@@ -360,7 +336,7 @@ func (r *GroupResource) ImportState(ctx context.Context, req resource.ImportStat
360336 resp .Diagnostics .AddError ("Client Error" , "Invalid import ID format, expected a single UUID or `<organization-name>/<group-name>`" )
361337 return
362338 }
363- group , err := client .Group (ctx , groupID )
339+ group , err := r . Client .Group (ctx , groupID )
364340 if err != nil {
365341 resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to get imported group, got error: %s" , err ))
366342 return
0 commit comments