Skip to content

Commit e544da5

Browse files
authored
fix: org unary invite & roles (#66)
1 parent dd68a83 commit e544da5

File tree

3 files changed

+132
-21
lines changed

3 files changed

+132
-21
lines changed

internal/apiclient/api.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,20 @@ paths:
124124
schema:
125125
$ref: "#/components/schemas/Invite"
126126
/v1/organizations/invites/{invite_id}:
127+
get:
128+
operationId: getInvite
129+
parameters:
130+
- name: invite_id
131+
in: path
132+
required: true
133+
schema:
134+
type: string
135+
responses:
136+
"200":
137+
content:
138+
application/json:
139+
schema:
140+
$ref: "#/components/schemas/Invite"
127141
delete:
128142
operationId: deleteInvite
129143
parameters:

internal/apiclient/apiclient.gen.go

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/provider/resource_organization_invite.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ func (r *OrganizationInviteResource) Schema(ctx context.Context, req resource.Sc
5050
},
5151
},
5252
"role": schema.StringAttribute{
53-
MarkdownDescription: "Role to assign to the invited user. Must be one of `user` or `developer`.",
53+
MarkdownDescription: "Role to assign to the invited user. Must be one of `user`, `developer`, `billing`, `admin`, or `claude_code_user`.",
5454
Required: true,
5555
Validators: []validator.String{
56-
stringvalidator.OneOf("user", "developer"),
56+
stringvalidator.OneOf("user", "developer", "billing", "admin", "claude_code_user"),
5757
},
5858
PlanModifiers: []planmodifier.String{
5959
stringplanmodifier.RequiresReplace(),
@@ -127,14 +127,17 @@ func (r *OrganizationInviteResource) Read(ctx context.Context, req resource.Read
127127
return
128128
}
129129

130-
// Note: The API doesn't provide a GET endpoint for individual invites
131-
// We need to list all invites and find the matching one
132-
httpResp, err := r.client.ListInvitesWithResponse(ctx, &apiclient.ListInvitesParams{})
130+
httpResp, err := r.client.GetInviteWithResponse(ctx, data.Id.ValueString())
133131
if err != nil {
134132
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read invite, got error: %s", err))
135133
return
136134
}
137135

136+
if httpResp.StatusCode() == http.StatusNotFound {
137+
resp.State.RemoveResource(ctx)
138+
return
139+
}
140+
138141
if httpResp.StatusCode() != http.StatusOK {
139142
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read invite, got status code %d: %s", httpResp.StatusCode(), string(httpResp.Body)))
140143
return
@@ -145,22 +148,7 @@ func (r *OrganizationInviteResource) Read(ctx context.Context, req resource.Read
145148
return
146149
}
147150

148-
// Find the invite by ID
149-
inviteId := data.Id.ValueString()
150-
var foundInvite *apiclient.Invite
151-
for _, invite := range httpResp.JSON200.Data {
152-
if invite.Id == inviteId {
153-
foundInvite = &invite
154-
break
155-
}
156-
}
157-
158-
if foundInvite == nil {
159-
resp.State.RemoveResource(ctx)
160-
return
161-
}
162-
163-
if err := data.Fill(*foundInvite); err != nil {
151+
if err := data.Fill(*httpResp.JSON200); err != nil {
164152
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to fill data: %s", err))
165153
return
166154
}

0 commit comments

Comments
 (0)