@@ -35,13 +35,13 @@ type GroupResource struct {
3535
3636// GroupResourceModel describes the resource data model.
3737type GroupResourceModel struct {
38- ID types. String `tfsdk:"id"`
38+ ID UUID `tfsdk:"id"`
3939
4040 Name types.String `tfsdk:"name"`
4141 DisplayName types.String `tfsdk:"display_name"`
4242 AvatarURL types.String `tfsdk:"avatar_url"`
4343 QuotaAllowance types.Int32 `tfsdk:"quota_allowance"`
44- OrganizationID types. String `tfsdk:"organization_id"`
44+ OrganizationID UUID `tfsdk:"organization_id"`
4545 Members types.Set `tfsdk:"members"`
4646}
4747
@@ -56,6 +56,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
5656 Attributes : map [string ]schema.Attribute {
5757 "id" : schema.StringAttribute {
5858 MarkdownDescription : "Group ID." ,
59+ CustomType : UUIDType ,
5960 Computed : true ,
6061 PlanModifiers : []planmodifier.String {
6162 stringplanmodifier .UseStateForUnknown (),
@@ -84,6 +85,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
8485 },
8586 "organization_id" : schema.StringAttribute {
8687 MarkdownDescription : "The organization ID that the group belongs to. Defaults to the provider default organization ID." ,
88+ CustomType : UUIDType ,
8789 Optional : true ,
8890 Computed : true ,
8991 PlanModifiers : []planmodifier.String {
@@ -92,7 +94,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
9294 },
9395 "members" : schema.SetAttribute {
9496 MarkdownDescription : "Members of the group, by ID. If null, members will not be added or removed." ,
95- ElementType : types . StringType ,
97+ ElementType : UUIDType ,
9698 Optional : true ,
9799 },
98100 },
@@ -132,14 +134,10 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
132134 client := r .data .Client
133135
134136 if data .OrganizationID .IsUnknown () {
135- data .OrganizationID = types . StringValue (r .data .DefaultOrganizationID )
137+ data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
136138 }
137139
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 ()
143141
144142 displayName := data .Name .ValueString ()
145143 if data .DisplayName .ValueString () != "" {
@@ -160,7 +158,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
160158 tflog .Trace (ctx , "successfully created group" , map [string ]any {
161159 "id" : group .ID .String (),
162160 })
163- data .ID = types . StringValue (group .ID . String () )
161+ data .ID = UUIDValue (group .ID )
164162 data .DisplayName = types .StringValue (group .DisplayName )
165163
166164 tflog .Trace (ctx , "setting group members" )
@@ -196,11 +194,7 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp
196194
197195 client := r .data .Client
198196
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 ()
204198
205199 group , err := client .Group (ctx , groupID )
206200 if err != nil {
@@ -212,13 +206,13 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp
212206 data .DisplayName = types .StringValue (group .DisplayName )
213207 data .AvatarURL = types .StringValue (group .AvatarURL )
214208 data .QuotaAllowance = types .Int32Value (int32 (group .QuotaAllowance ))
215- data .OrganizationID = types . StringValue (group .OrganizationID . String () )
209+ data .OrganizationID = UUIDValue (group .OrganizationID )
216210 if ! data .Members .IsNull () {
217211 members := make ([]attr.Value , 0 , len (group .Members ))
218212 for _ , member := range group .Members {
219- members = append (members , types . StringValue (member .ID . String () ))
213+ members = append (members , UUIDValue (member .ID ))
220214 }
221- data .Members = types .SetValueMust (types . StringType , members )
215+ data .Members = types .SetValueMust (UUIDType , members )
222216 }
223217
224218 // Save updated data into Terraform state
@@ -237,13 +231,9 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
237231
238232 client := r .data .Client
239233 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 )
246235 }
236+ groupID := data .ID .ValueUUID ()
247237
248238 group , err := client .Group (ctx , groupID )
249239 if err != nil {
@@ -301,14 +291,10 @@ func (r *GroupResource) Delete(ctx context.Context, req resource.DeleteRequest,
301291 }
302292
303293 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 ()
309295
310296 tflog .Trace (ctx , "deleting group" )
311- err = client .DeleteGroup (ctx , groupID )
297+ err : = client .DeleteGroup (ctx , groupID )
312298 if err != nil {
313299 resp .Diagnostics .AddError ("Client Error" , fmt .Sprintf ("Unable to delete group, got error: %s" , err ))
314300 return
0 commit comments