Skip to content

Commit e8c9955

Browse files
committed
Revert "Fix breaking APIs (#45)"
This reverts commit 2cc4322.
1 parent 940d9d3 commit e8c9955

File tree

15 files changed

+240
-220
lines changed

15 files changed

+240
-220
lines changed

docs/data-sources/organization_user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ description: |-
2222

2323
### Read-Only
2424

25-
- `created` (Number) The Unix timestamp when the user was added to the organization
25+
- `added_at` (Number) The Unix timestamp when the user was added to the organization
2626
- `id` (String) The ID of this resource.
2727
- `name` (String) The name of the user
2828
- `role` (String) The role of the user in the organization (owner, member, or reader)

docs/data-sources/organization_users.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ output "all_users_count" {
4646

4747
Read-Only:
4848

49-
- `created` (Number)
49+
- `added_at` (Number)
5050
- `email` (String)
5151
- `id` (String)
5252
- `name` (String)

docs/data-sources/project.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ output "project_id" {
2828
# Use project data to set variables
2929
locals {
3030
project_active = data.openai_project.production.status == "active"
31-
project_title = data.openai_project.production.title
31+
project_name = data.openai_project.production.name
3232
}
3333
```
3434

@@ -45,9 +45,17 @@ locals {
4545

4646
### Read-Only
4747

48-
- `archived_at` (Number) Timestamp when the project was archived (null if not archived)
49-
- `created` (Number) Timestamp when the project was created
48+
- `created_at` (Number) Timestamp when the project was created
5049
- `id` (String) The ID of this resource.
51-
- `is_initial` (Boolean) Whether this is the initial project
50+
- `name` (String) The name of the project
5251
- `status` (String) The status of the project
53-
- `title` (String) The title of the project
52+
- `usage_limits` (List of Object) Usage limits for the project (see [below for nested schema](#nestedatt--usage_limits))
53+
54+
<a id="nestedatt--usage_limits"></a>
55+
### Nested Schema for `usage_limits`
56+
57+
Read-Only:
58+
59+
- `max_monthly_dollars` (Number)
60+
- `max_parallel_requests` (Number)
61+
- `max_tokens` (Number)

docs/data-sources/projects.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ output "project_count" {
4242

4343
Read-Only:
4444

45-
- `archived_at` (Number)
46-
- `created` (Number)
45+
- `created_at` (Number)
4746
- `id` (String)
48-
- `is_initial` (Boolean)
47+
- `name` (String)
4948
- `status` (String)
50-
- `title` (String)

docs/resources/organization_user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ resource "openai_organization_user" "organization_users" {
4141

4242
### Read-Only
4343

44-
- `created` (Number) The Unix timestamp when the user was added to the organization
44+
- `added_at` (Number) The Unix timestamp when the user was added to the organization
4545
- `email` (String) The email address of the user
4646
- `id` (String) The ID of this resource.
4747
- `name` (String) The name of the user

docs/resources/project.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ description: |-
1515
```terraform
1616
# Create a new OpenAI project
1717
resource "openai_project" "development" {
18-
title = "Development Project"
18+
name = "Development Project"
19+
description = "Project for development and testing purposes"
1920
}
2021
2122
# Create a production project
2223
resource "openai_project" "production" {
23-
title = "Production API Services"
24+
name = "Production API Services"
25+
description = "Project for production API services and deployments"
2426
}
2527
2628
# Output the project ID
@@ -35,18 +37,18 @@ output "dev_project_id" {
3537

3638
### Required
3739

38-
- `title` (String) The title of the project
40+
- `name` (String) The name of the project
3941

4042
### Optional
4143

44+
- `description` (String) A description of the project
4245
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
4346

4447
### Read-Only
4548

46-
- `archived_at` (Number) Timestamp when the project was archived, if applicable
47-
- `created` (Number) Timestamp when the project was created
49+
- `archived_at` (String) Timestamp when the project was archived, if applicable
50+
- `created_at` (String) Timestamp when the project was created
4851
- `id` (String) The ID of this resource.
49-
- `is_initial` (Boolean) Whether this is the initial project
5052
- `status` (String) Status of the project (active, archived, etc.)
5153

5254
<a id="nestedblock--timeouts"></a>

examples/data-sources/openai_project/data-source.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ output "project_id" {
1313
# Use project data to set variables
1414
locals {
1515
project_active = data.openai_project.production.status == "active"
16-
project_title = data.openai_project.production.title
16+
project_name = data.openai_project.production.name
1717
}

examples/resources/openai_project/resource.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# Create a new OpenAI project
22
resource "openai_project" "development" {
3-
title = "Development Project"
3+
name = "Development Project"
4+
description = "Project for development and testing purposes"
45
}
56

67
# Create a production project
78
resource "openai_project" "production" {
8-
title = "Production API Services"
9+
name = "Production API Services"
10+
description = "Project for production API services and deployments"
911
}
1012

1113
# Output the project ID

internal/client/client.go

Lines changed: 66 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,19 @@ func (c *OpenAIClient) SetTimeout(timeout time.Duration) {
141141

142142
// Project represents a project in OpenAI
143143
type Project struct {
144-
ID string `json:"id"`
145-
Object string `json:"object"`
146-
Created int64 `json:"created"`
147-
Status string `json:"status"`
148-
ArchivedAt *int64 `json:"archived_at"`
149-
IsInitial bool `json:"is_initial"`
150-
Title string `json:"title"`
144+
Object string `json:"object"`
145+
ID string `json:"id"`
146+
Name string `json:"name"`
147+
Description string `json:"description,omitempty"`
148+
OrganizationID string `json:"organization_id,omitempty"`
149+
CreatedAt *int64 `json:"created_at"`
150+
ArchivedAt *int64 `json:"archived_at"`
151+
Status string `json:"status"`
152+
IsDefault bool `json:"is_default,omitempty"`
153+
BillingMode string `json:"billing_mode,omitempty"`
154+
APIKeys []APIKey `json:"api_keys,omitempty"`
155+
RateLimits []RateLimit `json:"rate_limits,omitempty"`
156+
Users []ProjectUser `json:"users,omitempty"`
151157
}
152158

153159
// ProjectUser represents a user associated with a project
@@ -191,7 +197,9 @@ type APIKey struct {
191197

192198
// CreateProjectRequest represents the request to create a project
193199
type CreateProjectRequest struct {
194-
Title string `json:"title"`
200+
Name string `json:"name"`
201+
Description string `json:"description,omitempty"`
202+
IsDefault bool `json:"is_default,omitempty"`
195203
}
196204

197205
// Error represents an error from the OpenAI API
@@ -559,64 +567,23 @@ type AssistantFunction struct {
559567
Parameters json.RawMessage `json:"parameters"`
560568
}
561569

562-
// UserInfo represents the nested user details in an organization user response
563-
type UserInfo struct {
564-
ID string `json:"id"`
565-
Object string `json:"object"`
566-
Email string `json:"email"`
567-
Name string `json:"name"`
568-
}
569-
570-
// OrganizationUser represents an OpenAI organization user as returned by the API
571-
type OrganizationUser struct {
572-
Object string `json:"object"`
573-
Created int64 `json:"created"`
574-
IsDefault bool `json:"is_default"`
575-
IsScaleTierAuthorizedPurchaser bool `json:"is_scale_tier_authorized_purchaser"`
576-
IsScimManaged bool `json:"is_scim_managed"`
577-
IsServiceAccount bool `json:"is_service_account"`
578-
Role string `json:"role"`
579-
User UserInfo `json:"user"`
580-
}
581-
582-
// User provides a flattened view of OrganizationUser for easier access
583-
// This is a convenience wrapper used internally
570+
// User represents an OpenAI user
584571
type User struct {
585-
ID string `json:"id"`
586-
Object string `json:"object"`
587-
Email string `json:"email"`
588-
Name string `json:"name"`
589-
Role string `json:"role"`
590-
Created int64 `json:"created"`
591-
IsDefault bool `json:"is_default"`
592-
IsScaleTierAuthorizedPurchaser bool `json:"is_scale_tier_authorized_purchaser"`
593-
IsScimManaged bool `json:"is_scim_managed"`
594-
IsServiceAccount bool `json:"is_service_account"`
595-
}
596-
597-
// ToUser converts an OrganizationUser to a flattened User struct
598-
func (ou *OrganizationUser) ToUser() *User {
599-
return &User{
600-
ID: ou.User.ID,
601-
Object: ou.Object,
602-
Email: ou.User.Email,
603-
Name: ou.User.Name,
604-
Role: ou.Role,
605-
Created: ou.Created,
606-
IsDefault: ou.IsDefault,
607-
IsScaleTierAuthorizedPurchaser: ou.IsScaleTierAuthorizedPurchaser,
608-
IsScimManaged: ou.IsScimManaged,
609-
IsServiceAccount: ou.IsServiceAccount,
610-
}
572+
ID string `json:"id"`
573+
Object string `json:"object"`
574+
Email string `json:"email"`
575+
Name string `json:"name"`
576+
Role string `json:"role"`
577+
AddedAt int64 `json:"added_at"`
611578
}
612579

613580
// UsersResponse represents the response from the list users API
614581
type UsersResponse struct {
615-
Object string `json:"object"`
616-
Data []OrganizationUser `json:"data"`
617-
FirstID string `json:"first_id"`
618-
LastID string `json:"last_id"`
619-
HasMore bool `json:"has_more"`
582+
Object string `json:"object"`
583+
Data []User `json:"data"`
584+
FirstID string `json:"first_id"`
585+
LastID string `json:"last_id"`
586+
HasMore bool `json:"has_more"`
620587
}
621588

622589
// ListUsers retrieves a list of users in the organization
@@ -693,13 +660,12 @@ func (c *OpenAIClient) FindUserByEmail(email string) (*User, bool, error) {
693660
return nil, false, nil
694661
}
695662

696-
// Return the first matching user (convert from OrganizationUser to User)
697-
orgUser := usersResponse.Data[0]
698-
user := orgUser.ToUser()
663+
// Return the first matching user
664+
user := usersResponse.Data[0]
699665

700666
// Double check that the email matches exactly (case insensitive)
701667
if strings.EqualFold(user.Email, email) {
702-
return user, true, nil
668+
return &user, true, nil
703669
}
704670

705671
// No exact match found
@@ -725,14 +691,13 @@ func (c *OpenAIClient) GetUser(userID string) (*User, bool, error) {
725691
return nil, false, fmt.Errorf("error getting user: %w", err)
726692
}
727693

728-
// Parse the response into OrganizationUser (new API format)
729-
var orgUser OrganizationUser
730-
if err := json.Unmarshal(respBody, &orgUser); err != nil {
694+
// Parse the response
695+
var user User
696+
if err := json.Unmarshal(respBody, &user); err != nil {
731697
return nil, false, fmt.Errorf("error decoding user response: %w", err)
732698
}
733699

734-
// Convert to flattened User struct
735-
return orgUser.ToUser(), true, nil
700+
return &user, true, nil
736701
}
737702

738703
// UpdateUserRole updates a user's role
@@ -754,14 +719,13 @@ func (c *OpenAIClient) UpdateUserRole(userID string, role string) (*User, error)
754719
return nil, fmt.Errorf("error updating user role: %w", err)
755720
}
756721

757-
// Parse the response into OrganizationUser (new API format)
758-
var orgUser OrganizationUser
759-
if err := json.Unmarshal(respBody, &orgUser); err != nil {
722+
// Parse the response
723+
var user User
724+
if err := json.Unmarshal(respBody, &user); err != nil {
760725
return nil, fmt.Errorf("error decoding user response: %w", err)
761726
}
762727

763-
// Convert to flattened User struct
764-
return orgUser.ToUser(), nil
728+
return &user, nil
765729
}
766730

767731
// DeleteUser removes a user from the organization
@@ -1111,15 +1075,25 @@ func (c *OpenAIClient) ListProjects(limit int, includeArchived bool, after strin
11111075
return &resp, nil
11121076
}
11131077

1114-
// CreateProject creates a new project with the given title
1115-
func (c *OpenAIClient) CreateProject(title string) (*Project, error) {
1078+
// CreateProject creates a new project with the given name and description
1079+
func (c *OpenAIClient) CreateProject(name, description string, isDefault bool) (*Project, error) {
11161080
// Create the request body
11171081
requestBody := map[string]interface{}{
1118-
"title": title,
1082+
"name": name,
1083+
}
1084+
1085+
// Only include description if it's not empty
1086+
if description != "" {
1087+
requestBody["description"] = description
1088+
}
1089+
1090+
// Only include is_default if it's true (don't send false)
1091+
if isDefault {
1092+
requestBody["is_default"] = isDefault
11191093
}
11201094

11211095
// Debug information
1122-
fmt.Printf("Creating project with title: %s\n", title)
1096+
fmt.Printf("Creating project with name: %s\n", name)
11231097
fmt.Printf("Request body: %+v\n", requestBody)
11241098

11251099
// Use the exact endpoint from the curl command that works
@@ -1166,11 +1140,21 @@ func (c *OpenAIClient) GetProject(id string) (*Project, error) {
11661140
return &project, nil
11671141
}
11681142

1169-
// UpdateProject updates an existing project with the given title
1170-
func (c *OpenAIClient) UpdateProject(id, title string) (*Project, error) {
1143+
// UpdateProject updates an existing project with the given details
1144+
func (c *OpenAIClient) UpdateProject(id, name, description string, isDefault bool) (*Project, error) {
11711145
// Create the request body
11721146
requestBody := map[string]interface{}{
1173-
"title": title,
1147+
"name": name,
1148+
}
1149+
1150+
// Only include description if it's not empty
1151+
if description != "" {
1152+
requestBody["description"] = description
1153+
}
1154+
1155+
// Only include is_default if it's true (don't send false)
1156+
if isDefault {
1157+
requestBody["is_default"] = isDefault
11741158
}
11751159

11761160
// Use the exact endpoint structure consistent with the curl command

internal/provider/data_source_openai_organization_user.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func dataSourceOpenAIOrganizationUser() *schema.Resource {
3838
Computed: true,
3939
Description: "The role of the user in the organization (owner, member, or reader)",
4040
},
41-
"created": {
41+
"added_at": {
4242
Type: schema.TypeInt,
4343
Computed: true,
4444
Description: "The Unix timestamp when the user was added to the organization",
@@ -114,8 +114,8 @@ func dataSourceOpenAIOrganizationUserRead(ctx context.Context, d *schema.Resourc
114114
return diag.FromErr(fmt.Errorf("error setting role: %s", err))
115115
}
116116

117-
if err := d.Set("created", user.Created); err != nil {
118-
return diag.FromErr(fmt.Errorf("error setting created: %s", err))
117+
if err := d.Set("added_at", user.AddedAt); err != nil {
118+
return diag.FromErr(fmt.Errorf("error setting added_at: %s", err))
119119
}
120120

121121
return nil

0 commit comments

Comments
 (0)