55 "fmt"
66
77 "github.com/coder/coder/v2/codersdk"
8+ "github.com/coder/terraform-provider-coderd/internal"
89 "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
910 "github.com/hashicorp/terraform-plugin-framework/datasource"
1011 "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
@@ -28,9 +29,9 @@ type GroupDataSource struct {
2829// GroupDataSourceModel describes the data source data model.
2930type GroupDataSourceModel struct {
3031 // 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"`
3435
3536 DisplayName types.String `tfsdk:"display_name"`
3637 AvatarURL types.String `tfsdk:"avatar_url"`
@@ -40,14 +41,14 @@ type GroupDataSourceModel struct {
4041}
4142
4243type 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"`
5152}
5253
5354func (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
6364 MarkdownDescription : "The ID of the group to retrieve. This field will be populated if a name and organization ID is supplied." ,
6465 Optional : true ,
6566 Computed : true ,
66- CustomType : UUIDType ,
67+ CustomType : internal . UUIDType ,
6768 Validators : []validator.String {
6869 stringvalidator .AtLeastOneOf (path.Expressions {
6970 path .MatchRoot ("name" ),
@@ -78,7 +79,7 @@ func (d *GroupDataSource) Schema(ctx context.Context, req datasource.SchemaReque
7879 },
7980 "organization_id" : schema.StringAttribute {
8081 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 ,
8283 Optional : true ,
8384 Computed : true ,
8485 },
@@ -102,7 +103,7 @@ func (d *GroupDataSource) Schema(ctx context.Context, req datasource.SchemaReque
102103 NestedObject : schema.NestedAttributeObject {
103104 Attributes : map [string ]schema.Attribute {
104105 "id" : schema.StringAttribute {
105- CustomType : UUIDType ,
106+ CustomType : internal . UUIDType ,
106107 Computed : true ,
107108 },
108109 "username" : schema.StringAttribute {
@@ -176,7 +177,7 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
176177 client := d .data .Client
177178
178179 if data .OrganizationID .IsNull () {
179- data .OrganizationID = UUIDValue (d .data .DefaultOrganizationID )
180+ data .OrganizationID = internal . UUIDValue (d .data .DefaultOrganizationID )
180181 }
181182
182183 var (
@@ -187,7 +188,7 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
187188 groupID := data .ID .ValueUUID ()
188189 group , err = client .Group (ctx , groupID )
189190 if err != nil {
190- if isNotFound (err ) {
191+ if internal . IsNotFound (err ) {
191192 resp .Diagnostics .AddWarning ("Client Warning" , fmt .Sprintf ("Group with ID %s not found. Marking as deleted." , groupID .String ()))
192193 resp .State .RemoveResource (ctx )
193194 return
@@ -196,19 +197,19 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
196197 return
197198 }
198199 data .Name = types .StringValue (group .Name )
199- data .OrganizationID = UUIDValue (group .OrganizationID )
200+ data .OrganizationID = internal . UUIDValue (group .OrganizationID )
200201 } else {
201202 group , err = client .GroupByOrgAndName (ctx , data .OrganizationID .ValueUUID (), data .Name .ValueString ())
202203 if err != nil {
203- if isNotFound (err ) {
204+ if internal . IsNotFound (err ) {
204205 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 ()))
205206 resp .State .RemoveResource (ctx )
206207 return
207208 }
208209 resp .Diagnostics .AddError ("Failed to get group by name and org ID" , err .Error ())
209210 return
210211 }
211- data .ID = UUIDValue (group .ID )
212+ data .ID = internal . UUIDValue (group .ID )
212213 }
213214
214215 data .DisplayName = types .StringValue (group .DisplayName )
@@ -217,7 +218,7 @@ func (d *GroupDataSource) Read(ctx context.Context, req datasource.ReadRequest,
217218 members := make ([]Member , 0 , len (group .Members ))
218219 for _ , member := range group .Members {
219220 members = append (members , Member {
220- ID : UUIDValue (member .ID ),
221+ ID : internal . UUIDValue (member .ID ),
221222 Username : types .StringValue (member .Username ),
222223 Email : types .StringValue (member .Email ),
223224 CreatedAt : types .Int64Value (member .CreatedAt .Unix ()),
0 commit comments