5
5
"fmt"
6
6
7
7
"github.com/coder/coder/v2/codersdk"
8
+ "github.com/coder/terraform-provider-coderd/internal"
8
9
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
9
10
"github.com/hashicorp/terraform-plugin-framework/datasource"
10
11
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
@@ -28,9 +29,9 @@ type GroupDataSource struct {
28
29
// GroupDataSourceModel describes the data source data model.
29
30
type GroupDataSourceModel struct {
30
31
// ID or name and organization ID must be set
31
- ID UUID `tfsdk:"id"`
32
- Name types.String `tfsdk:"name"`
33
- OrganizationID UUID `tfsdk:"organization_id"`
32
+ ID internal. UUID `tfsdk:"id"`
33
+ Name types.String `tfsdk:"name"`
34
+ OrganizationID internal. UUID `tfsdk:"organization_id"`
34
35
35
36
DisplayName types.String `tfsdk:"display_name"`
36
37
AvatarURL types.String `tfsdk:"avatar_url"`
@@ -40,14 +41,14 @@ type GroupDataSourceModel struct {
40
41
}
41
42
42
43
type Member struct {
43
- ID UUID `tfsdk:"id"`
44
- Username types.String `tfsdk:"username"`
45
- Email types.String `tfsdk:"email"`
46
- CreatedAt types.Int64 `tfsdk:"created_at"`
47
- LastSeenAt types.Int64 `tfsdk:"last_seen_at"`
48
- Status types.String `tfsdk:"status"`
49
- LoginType types.String `tfsdk:"login_type"`
50
- ThemePreference types.String `tfsdk:"theme_preference"`
44
+ ID internal. UUID `tfsdk:"id"`
45
+ Username types.String `tfsdk:"username"`
46
+ Email types.String `tfsdk:"email"`
47
+ CreatedAt types.Int64 `tfsdk:"created_at"`
48
+ LastSeenAt types.Int64 `tfsdk:"last_seen_at"`
49
+ Status types.String `tfsdk:"status"`
50
+ LoginType types.String `tfsdk:"login_type"`
51
+ ThemePreference types.String `tfsdk:"theme_preference"`
51
52
}
52
53
53
54
func (d * GroupDataSource ) Metadata (ctx context.Context , req datasource.MetadataRequest , resp * datasource.MetadataResponse ) {
@@ -63,7 +64,7 @@ func (d *GroupDataSource) Schema(ctx context.Context, req datasource.SchemaReque
63
64
MarkdownDescription : "The ID of the group to retrieve. This field will be populated if a name and organization ID is supplied." ,
64
65
Optional : true ,
65
66
Computed : true ,
66
- CustomType : UUIDType ,
67
+ CustomType : internal . UUIDType ,
67
68
Validators : []validator.String {
68
69
stringvalidator .AtLeastOneOf (path.Expressions {
69
70
path .MatchRoot ("name" ),
@@ -78,7 +79,7 @@ func (d *GroupDataSource) Schema(ctx context.Context, req datasource.SchemaReque
78
79
},
79
80
"organization_id" : schema.StringAttribute {
80
81
MarkdownDescription : "The organization ID that the group belongs to. This field will be populated if an ID is supplied. Defaults to the provider default organization ID." ,
81
- CustomType : UUIDType ,
82
+ CustomType : internal . UUIDType ,
82
83
Optional : true ,
83
84
Computed : true ,
84
85
},
@@ -102,7 +103,7 @@ func (d *GroupDataSource) Schema(ctx context.Context, req datasource.SchemaReque
102
103
NestedObject : schema.NestedAttributeObject {
103
104
Attributes : map [string ]schema.Attribute {
104
105
"id" : schema.StringAttribute {
105
- CustomType : UUIDType ,
106
+ CustomType : internal . UUIDType ,
106
107
Computed : true ,
107
108
},
108
109
"username" : schema.StringAttribute {
@@ -176,7 +177,7 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
176
177
client := d .data .Client
177
178
178
179
if data .OrganizationID .IsNull () {
179
- data .OrganizationID = UUIDValue (d .data .DefaultOrganizationID )
180
+ data .OrganizationID = internal . UUIDValue (d .data .DefaultOrganizationID )
180
181
}
181
182
182
183
var (
@@ -187,7 +188,7 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
187
188
groupID := data .ID .ValueUUID ()
188
189
group , err = client .Group (ctx , groupID )
189
190
if err != nil {
190
- if isNotFound (err ) {
191
+ if internal . IsNotFound (err ) {
191
192
resp .Diagnostics .AddWarning ("Client Warning" , fmt .Sprintf ("Group with ID %s not found. Marking as deleted." , groupID .String ()))
192
193
resp .State .RemoveResource (ctx )
193
194
return
@@ -196,19 +197,19 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
196
197
return
197
198
}
198
199
data .Name = types .StringValue (group .Name )
199
- data .OrganizationID = UUIDValue (group .OrganizationID )
200
+ data .OrganizationID = internal . UUIDValue (group .OrganizationID )
200
201
} else {
201
202
group , err = client .GroupByOrgAndName (ctx , data .OrganizationID .ValueUUID (), data .Name .ValueString ())
202
203
if err != nil {
203
- if isNotFound (err ) {
204
+ if internal . IsNotFound (err ) {
204
205
resp .Diagnostics .AddWarning ("Client Warning" , fmt .Sprintf ("Group with name %s not found in organization with ID %s. Marking as deleted." , data .Name .ValueString (), data .OrganizationID .ValueString ()))
205
206
resp .State .RemoveResource (ctx )
206
207
return
207
208
}
208
209
resp .Diagnostics .AddError ("Failed to get group by name and org ID" , err .Error ())
209
210
return
210
211
}
211
- data .ID = UUIDValue (group .ID )
212
+ data .ID = internal . UUIDValue (group .ID )
212
213
}
213
214
214
215
data .DisplayName = types .StringValue (group .DisplayName )
@@ -217,7 +218,7 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
217
218
members := make ([]Member , 0 , len (group .Members ))
218
219
for _ , member := range group .Members {
219
220
members = append (members , Member {
220
- ID : UUIDValue (member .ID ),
221
+ ID : internal . UUIDValue (member .ID ),
221
222
Username : types .StringValue (member .Username ),
222
223
Email : types .StringValue (member .Email ),
223
224
CreatedAt : types .Int64Value (member .CreatedAt .Unix ()),
0 commit comments