6
6
"strings"
7
7
8
8
"github.com/coder/coder/v2/codersdk"
9
+ "github.com/coder/terraform-provider-coderd/internal"
9
10
"github.com/coder/terraform-provider-coderd/internal/codersdkvalidator"
10
11
"github.com/google/uuid"
11
12
"github.com/hashicorp/terraform-plugin-framework/attr"
@@ -37,14 +38,14 @@ type GroupResource struct {
37
38
38
39
// GroupResourceModel describes the resource data model.
39
40
type GroupResourceModel struct {
40
- ID UUID `tfsdk:"id"`
41
-
42
- Name types.String `tfsdk:"name"`
43
- DisplayName types.String `tfsdk:"display_name"`
44
- AvatarURL types.String `tfsdk:"avatar_url"`
45
- QuotaAllowance types.Int32 `tfsdk:"quota_allowance"`
46
- OrganizationID UUID `tfsdk:"organization_id"`
47
- Members types.Set `tfsdk:"members"`
41
+ ID internal. UUID `tfsdk:"id"`
42
+
43
+ Name types.String `tfsdk:"name"`
44
+ DisplayName types.String `tfsdk:"display_name"`
45
+ AvatarURL types.String `tfsdk:"avatar_url"`
46
+ QuotaAllowance types.Int32 `tfsdk:"quota_allowance"`
47
+ OrganizationID internal. UUID `tfsdk:"organization_id"`
48
+ Members types.Set `tfsdk:"members"`
48
49
}
49
50
50
51
func CheckGroupEntitlements (ctx context.Context , features map [codersdk.FeatureName ]codersdk.Feature ) (diags diag.Diagnostics ) {
@@ -67,7 +68,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
67
68
Attributes : map [string ]schema.Attribute {
68
69
"id" : schema.StringAttribute {
69
70
MarkdownDescription : "Group ID." ,
70
- CustomType : UUIDType ,
71
+ CustomType : internal . UUIDType ,
71
72
Computed : true ,
72
73
PlanModifiers : []planmodifier.String {
73
74
stringplanmodifier .UseStateForUnknown (),
@@ -104,7 +105,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
104
105
},
105
106
"organization_id" : schema.StringAttribute {
106
107
MarkdownDescription : "The organization ID that the group belongs to. Defaults to the provider default organization ID." ,
107
- CustomType : UUIDType ,
108
+ CustomType : internal . UUIDType ,
108
109
Optional : true ,
109
110
Computed : true ,
110
111
PlanModifiers : []planmodifier.String {
@@ -113,7 +114,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
113
114
},
114
115
"members" : schema.SetAttribute {
115
116
MarkdownDescription : "Members of the group, by ID. If `null`, members will not be added or removed by Terraform. To have a group resource with unmanaged members, but be able to read the members in Terraform, use `data.coderd_group`" ,
116
- ElementType : UUIDType ,
117
+ ElementType : internal . UUIDType ,
117
118
Optional : true ,
118
119
},
119
120
},
@@ -141,9 +142,8 @@ func (r *GroupResource) Configure(ctx context.Context, req resource.ConfigureReq
141
142
}
142
143
143
144
func (r * GroupResource ) Create (ctx context.Context , req resource.CreateRequest , resp * resource.CreateResponse ) {
144
- var data GroupResourceModel
145
-
146
145
// Read Terraform plan data into the model
146
+ var data GroupResourceModel
147
147
resp .Diagnostics .Append (req .Plan .Get (ctx , & data )... )
148
148
149
149
if resp .Diagnostics .HasError () {
@@ -158,7 +158,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
158
158
client := r .data .Client
159
159
160
160
if data .OrganizationID .IsUnknown () {
161
- data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
161
+ data .OrganizationID = internal . UUIDValue (r .data .DefaultOrganizationID )
162
162
}
163
163
164
164
orgID := data .OrganizationID .ValueUUID ()
@@ -177,7 +177,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
177
177
tflog .Info (ctx , "successfully created group" , map [string ]any {
178
178
"id" : group .ID .String (),
179
179
})
180
- data .ID = UUIDValue (group .ID )
180
+ data .ID = internal . UUIDValue (group .ID )
181
181
data .DisplayName = types .StringValue (group .DisplayName )
182
182
183
183
tflog .Info (ctx , "setting group members" )
@@ -217,7 +217,7 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp
217
217
218
218
group , err := client .Group (ctx , groupID )
219
219
if err != nil {
220
- if isNotFound (err ) {
220
+ if internal . IsNotFound (err ) {
221
221
resp .Diagnostics .AddWarning ("Client Warning" , fmt .Sprintf ("Group with ID %s not found. Marking as deleted." , groupID .String ()))
222
222
resp .State .RemoveResource (ctx )
223
223
return
@@ -230,13 +230,13 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp
230
230
data .DisplayName = types .StringValue (group .DisplayName )
231
231
data .AvatarURL = types .StringValue (group .AvatarURL )
232
232
data .QuotaAllowance = types .Int32Value (int32 (group .QuotaAllowance ))
233
- data .OrganizationID = UUIDValue (group .OrganizationID )
233
+ data .OrganizationID = internal . UUIDValue (group .OrganizationID )
234
234
if ! data .Members .IsNull () {
235
235
members := make ([]attr.Value , 0 , len (group .Members ))
236
236
for _ , member := range group .Members {
237
- members = append (members , UUIDValue (member .ID ))
237
+ members = append (members , internal . UUIDValue (member .ID ))
238
238
}
239
- data .Members = types .SetValueMust (UUIDType , members )
239
+ data .Members = types .SetValueMust (internal . UUIDType , members )
240
240
}
241
241
242
242
// Save updated data into Terraform state
@@ -255,7 +255,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
255
255
256
256
client := r .data .Client
257
257
if data .OrganizationID .IsUnknown () {
258
- data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
258
+ data .OrganizationID = internal . UUIDValue (r .data .DefaultOrganizationID )
259
259
}
260
260
groupID := data .ID .ValueUUID ()
261
261
@@ -267,7 +267,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
267
267
var add []string
268
268
var remove []string
269
269
if ! data .Members .IsNull () {
270
- var plannedMembers []UUID
270
+ var plannedMembers []internal. UUID
271
271
resp .Diagnostics .Append (
272
272
data .Members .ElementsAs (ctx , & plannedMembers , false )... ,
273
273
)
0 commit comments