Skip to content

Commit 1698038

Browse files
authored
Revert "remove projectId from user token resource (#528)" (#566)
This reverts commit 4b066a8.
1 parent db88001 commit 1698038

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

client/user_token.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ type UserToken struct {
2020
ExpiresAt *int64 `json:"expiresAt"`
2121
LeakedAt *int64 `json:"leakedAt"`
2222
LeakedURL *string `json:"leakedUrl"`
23+
ProjectID *string `json:"projectId"`
2324
BearerToken *string
2425
}
2526

2627
type CreateUserTokenRequest struct {
27-
Name string `json:"name"`
28-
ExpiresAt *int64 `json:"expiresAt,omitempty"`
29-
TeamID string `json:"-"`
28+
Name string `json:"name"`
29+
ExpiresAt *int64 `json:"expiresAt,omitempty"`
30+
ProjectID *string `json:"projectId,omitempty"`
31+
TeamID string `json:"-"`
3032
}
3133

3234
func (c *Client) CreateUserToken(ctx context.Context, request CreateUserTokenRequest) (u UserToken, err error) {

docs/resources/user_token.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ resource "vercel_user_token" "example_expiring" {
4242
### Optional
4343

4444
- `expires_at` (Number) The Unix timestamp in milliseconds when the token should expire.
45+
- `project_id` (String) The ID of the project this token should be scoped to. Requires team scope.
4546
- `team_id` (String) The ID of the Vercel team scope for this token. Required when creating a team-scoped token if a default team has not been set in the provider.
4647

4748
### Read-Only

vercel/resource_user_token.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ The ` + "`bearer_token`" + ` value is only returned during creation and cannot b
8888
int64validator.AtLeast(1),
8989
},
9090
},
91+
"project_id": schema.StringAttribute{
92+
Description: "The ID of the project this token should be scoped to. Requires team scope.",
93+
Optional: true,
94+
PlanModifiers: []planmodifier.String{stringplanmodifier.RequiresReplace()},
95+
},
9196
"team_id": schema.StringAttribute{
9297
Description: "The ID of the Vercel team scope for this token. Required when creating a team-scoped token if a default team has not been set in the provider.",
9398
Optional: true,
@@ -148,6 +153,7 @@ type UserToken struct {
148153
ID types.String `tfsdk:"id"`
149154
Name types.String `tfsdk:"name"`
150155
ExpiresAt types.Int64 `tfsdk:"expires_at"`
156+
ProjectID types.String `tfsdk:"project_id"`
151157
TeamID types.String `tfsdk:"team_id"`
152158
BearerToken types.String `tfsdk:"bearer_token"`
153159
Type types.String `tfsdk:"type"`
@@ -169,6 +175,7 @@ func responseToUserToken(out client.UserToken, bearerToken types.String) UserTok
169175
ID: types.StringValue(out.ID),
170176
Name: types.StringValue(out.Name),
171177
ExpiresAt: types.Int64PointerValue(out.ExpiresAt),
178+
ProjectID: types.StringPointerValue(out.ProjectID),
172179
TeamID: types.StringPointerValue(out.TeamID),
173180
BearerToken: bearerToken,
174181
Type: types.StringValue(out.Type),
@@ -207,9 +214,19 @@ func (r *userTokenResource) Create(ctx context.Context, req resource.CreateReque
207214
)
208215
return
209216
}
217+
if !plan.ProjectID.IsNull() && r.client.TeamID(plan.TeamID.ValueString()) == "" {
218+
resp.Diagnostics.AddAttributeError(
219+
path.Root("project_id"),
220+
"Project-scoped token requires team scope",
221+
"`project_id` can only be used when the token is created in a team scope. Set `team_id` or configure a default team on the provider.",
222+
)
223+
return
224+
}
225+
210226
out, err := r.client.CreateUserToken(ctx, client.CreateUserTokenRequest{
211227
Name: name,
212228
ExpiresAt: plan.ExpiresAt.ValueInt64Pointer(),
229+
ProjectID: plan.ProjectID.ValueStringPointer(),
213230
TeamID: plan.TeamID.ValueString(),
214231
})
215232
if err != nil {

0 commit comments

Comments
 (0)