66"strings"
77
88"github.com/coder/coder/v2/codersdk"
9+ "github.com/coder/terraform-provider-coderd/internal"
910"github.com/coder/terraform-provider-coderd/internal/codersdkvalidator"
1011"github.com/google/uuid"
1112"github.com/hashicorp/terraform-plugin-framework/attr"
@@ -37,14 +38,14 @@ type GroupResource struct {
3738
3839// GroupResourceModel describes the resource data model.
3940type 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"`
4849}
4950
5051func 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,
6768Attributes :map [string ]schema.Attribute {
6869"id" : schema.StringAttribute {
6970MarkdownDescription :"Group ID." ,
70- CustomType :UUIDType ,
71+ CustomType :internal . UUIDType ,
7172Computed :true ,
7273PlanModifiers : []planmodifier.String {
7374stringplanmodifier .UseStateForUnknown (),
@@ -104,7 +105,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
104105},
105106"organization_id" : schema.StringAttribute {
106107MarkdownDescription :"The organization ID that the group belongs to. Defaults to the provider default organization ID." ,
107- CustomType :UUIDType ,
108+ CustomType :internal . UUIDType ,
108109Optional :true ,
109110Computed :true ,
110111PlanModifiers : []planmodifier.String {
@@ -113,7 +114,7 @@ func (r *GroupResource) Schema(ctx context.Context, req resource.SchemaRequest,
113114},
114115"members" : schema.SetAttribute {
115116MarkdownDescription :"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 ,
117118Optional :true ,
118119},
119120},
@@ -141,9 +142,8 @@ func (r *GroupResource) Configure(ctx context.Context, req resource.ConfigureReq
141142}
142143
143144func (r * GroupResource )Create (ctx context.Context ,req resource.CreateRequest ,resp * resource.CreateResponse ) {
144- var data GroupResourceModel
145-
146145// Read Terraform plan data into the model
146+ var data GroupResourceModel
147147resp .Diagnostics .Append (req .Plan .Get (ctx ,& data )... )
148148
149149if resp .Diagnostics .HasError () {
@@ -158,7 +158,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
158158client := r .data .Client
159159
160160if data .OrganizationID .IsUnknown () {
161- data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
161+ data .OrganizationID = internal . UUIDValue (r .data .DefaultOrganizationID )
162162}
163163
164164orgID := data .OrganizationID .ValueUUID ()
@@ -177,7 +177,7 @@ func (r *GroupResource) Create(ctx context.Context, req resource.CreateRequest,
177177tflog .Info (ctx ,"successfully created group" ,map [string ]any {
178178"id" :group .ID .String (),
179179})
180- data .ID = UUIDValue (group .ID )
180+ data .ID = internal . UUIDValue (group .ID )
181181data .DisplayName = types .StringValue (group .DisplayName )
182182
183183tflog .Info (ctx ,"setting group members" )
@@ -217,7 +217,7 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp
217217
218218group ,err := client .Group (ctx ,groupID )
219219if err != nil {
220- if isNotFound (err ) {
220+ if internal . IsNotFound (err ) {
221221resp .Diagnostics .AddWarning ("Client Warning" ,fmt .Sprintf ("Group with ID %s not found. Marking as deleted." ,groupID .String ()))
222222resp .State .RemoveResource (ctx )
223223return
@@ -230,13 +230,13 @@ func (r *GroupResource) Read(ctx context.Context, req resource.ReadRequest, resp
230230data .DisplayName = types .StringValue (group .DisplayName )
231231data .AvatarURL = types .StringValue (group .AvatarURL )
232232data .QuotaAllowance = types .Int32Value (int32 (group .QuotaAllowance ))
233- data .OrganizationID = UUIDValue (group .OrganizationID )
233+ data .OrganizationID = internal . UUIDValue (group .OrganizationID )
234234if ! data .Members .IsNull () {
235235members := make ([]attr.Value ,0 ,len (group .Members ))
236236for _ ,member := range group .Members {
237- members = append (members ,UUIDValue (member .ID ))
237+ members = append (members ,internal . UUIDValue (member .ID ))
238238}
239- data .Members = types .SetValueMust (UUIDType ,members )
239+ data .Members = types .SetValueMust (internal . UUIDType ,members )
240240}
241241
242242// Save updated data into Terraform state
@@ -255,7 +255,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
255255
256256client := r .data .Client
257257if data .OrganizationID .IsUnknown () {
258- data .OrganizationID = UUIDValue (r .data .DefaultOrganizationID )
258+ data .OrganizationID = internal . UUIDValue (r .data .DefaultOrganizationID )
259259}
260260groupID := data .ID .ValueUUID ()
261261
@@ -267,7 +267,7 @@ func (r *GroupResource) Update(ctx context.Context, req resource.UpdateRequest,
267267var add []string
268268var remove []string
269269if ! data .Members .IsNull () {
270- var plannedMembers []UUID
270+ var plannedMembers []internal. UUID
271271resp .Diagnostics .Append (
272272data .Members .ElementsAs (ctx ,& plannedMembers ,false )... ,
273273)