@@ -35,13 +35,13 @@ type GroupResource struct {
35
35
36
36
// GroupResourceModel describes the resource data model.
37
37
type GroupResourceModel struct {
38
- ID types. String `tfsdk:"id"`
38
+ ID UUID `tfsdk:"id"`
39
39
40
40
Name types.String `tfsdk:"name"`
41
41
DisplayName types.String `tfsdk:"display_name"`
42
42
AvatarURL types.String `tfsdk:"avatar_url"`
43
43
QuotaAllowance types.Int32 `tfsdk:"quota_allowance"`
44
- OrganizationID types. String `tfsdk:"organization_id"`
44
+ OrganizationID UUID `tfsdk:"organization_id"`
45
45
Members types.Set `tfsdk:"members"`
46
46
}
47
47
@@ -56,6 +56,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
56
56
Attributes : map [string ]schema.Attribute {
57
57
"id" : schema.StringAttribute {
58
58
MarkdownDescription : "Group ID." ,
59
+ CustomType : UUIDType ,
59
60
Computed : true ,
60
61
PlanModifiers : []planmodifier.String {
61
62
stringplanmodifier .UseStateForUnknown (),
@@ -84,6 +85,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
84
85
},
85
86
"organization_id" : schema.StringAttribute {
86
87
MarkdownDescription : "The organization ID that the group belongs to. Defaults to the provider default organization ID." ,
88
+ CustomType : UUIDType ,
87
89
Optional : true ,
88
90
Computed : true ,
89
91
PlanModifiers : []planmodifier.String {
@@ -92,7 +94,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
92
94
},
93
95
"members" : schema.SetAttribute {
94
96
MarkdownDescription : "Members of the group, by ID. If null, members will not be added or removed." ,
95
- ElementType : types . StringType ,
97
+ ElementType : UUIDType ,
96
98
Optional : true ,
97
99
},
98
100
},
@@ -132,14 +134,10 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
132
134
client := r .data .Client
133
135
134
136
if data .OrganizationID .IsUnknown () {
135
- data .OrganizationID = types . StringValue (r .data .DefaultOrganizationID )
137
+ data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
136
138
}
137
139
138
- orgID , err := uuid .Parse (data .OrganizationID .ValueString ())
139
- if err != nil {
140
- resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to parse supplied organization ID as UUID, got error: %s" , err ))
141
- return
142
- }
140
+ orgID := data .OrganizationID .ValueUUID ()
143
141
144
142
displayName := data .Name .ValueString ()
145
143
if data .DisplayName .ValueString () != "" {
@@ -160,7 +158,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
160
158
tflog .Trace (ctx , "successfully created group" , map [string ]any {
161
159
"id" : group .ID .String (),
162
160
})
163
- data .ID = types . StringValue (group .ID . String () )
161
+ data .ID = UUIDValue (group .ID )
164
162
data .DisplayName = types .StringValue (group .DisplayName )
165
163
166
164
tflog .Trace (ctx , "setting group members" )
@@ -196,11 +194,7 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp
196
194
197
195
client := r .data .Client
198
196
199
- groupID , err := uuid .Parse (data .ID .ValueString ())
200
- if err != nil {
201
- resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to parse supplied group ID as UUID, got error: %s" , err ))
202
- return
203
- }
197
+ groupID := data .ID .ValueUUID ()
204
198
205
199
group , err := client .Group (ctx , groupID )
206
200
if err != nil {
@@ -212,13 +206,13 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp
212
206
data .DisplayName = types .StringValue (group .DisplayName )
213
207
data .AvatarURL = types .StringValue (group .AvatarURL )
214
208
data .QuotaAllowance = types .Int32Value (int32 (group .QuotaAllowance ))
215
- data .OrganizationID = types . StringValue (group .OrganizationID . String () )
209
+ data .OrganizationID = UUIDValue (group .OrganizationID )
216
210
if ! data .Members .IsNull () {
217
211
members := make ([]attr.Value , 0 , len (group .Members ))
218
212
for _ , member := range group .Members {
219
- members = append (members , types . StringValue (member .ID . String () ))
213
+ members = append (members , UUIDValue (member .ID ))
220
214
}
221
- data .Members = types .SetValueMust (types . StringType , members )
215
+ data .Members = types .SetValueMust (UUIDType , members )
222
216
}
223
217
224
218
// Save updated data into Terraform state
@@ -237,13 +231,9 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
237
231
238
232
client := r .data .Client
239
233
if data .OrganizationID .IsUnknown () {
240
- data .OrganizationID = types .StringValue (r .data .DefaultOrganizationID )
241
- }
242
- groupID , err := uuid .Parse (data .ID .ValueString ())
243
- if err != nil {
244
- resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to parse supplied group ID as UUID, got error: %s" , err ))
245
- return
234
+ data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
246
235
}
236
+ groupID := data .ID .ValueUUID ()
247
237
248
238
group , err := client .Group (ctx , groupID )
249
239
if err != nil {
@@ -301,14 +291,10 @@ func (r *GroupResource) Delete(ctx context.Context, req resource.DeleteRequest,
301
291
}
302
292
303
293
client := r .data .Client
304
- groupID , err := uuid .Parse (data .ID .ValueString ())
305
- if err != nil {
306
- resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to parse supplied group ID as UUID, got error: %s" , err ))
307
- return
308
- }
294
+ groupID := data .ID .ValueUUID ()
309
295
310
296
tflog .Trace (ctx , "deleting group" )
311
- err = client .DeleteGroup (ctx , groupID )
297
+ err : = client .DeleteGroup (ctx , groupID )
312
298
if err != nil {
313
299
resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to delete group, got error: %s" , err ))
314
300
return
0 commit comments