Skip to content

Commit

Permalink
Merge pull request #87 from offirt/patch-2
Browse files Browse the repository at this point in the history
Modify Assistant - Take existing id from the state instead of the plan
  • Loading branch information
skyscrapr authored May 27, 2024
2 parents 658b3c6 + 110c651 commit a32166f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions openai/assistant_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,15 @@ func (r *AssistantResource) Update(ctx context.Context, req resource.UpdateReque
// Read Terraform plan data into the model
resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...)

var state OpenAIAssistantResourceModel
// Read Terraform prior state data into the model
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)

if resp.Diagnostics.HasError() {
return
}

tflog.Info(ctx, "Updating Assistant...")
tflog.Info(ctx, fmt.Sprintf("Updating Assistant: %s", state.Id.ValueString()))

aReq := openai.AssistantRequest{
Model: data.Model.ValueString(),
Expand All @@ -257,7 +261,7 @@ func (r *AssistantResource) Update(ctx context.Context, req resource.UpdateReque
aReq.Tools = expandAssistantTools(toolModels)
aReq.ToolResources = expandAssistantToolResources(ctx, data.ToolResources)

assistant, err := r.client.Assistants().ModifyAssistant(data.Id.ValueString(), &aReq)
assistant, err := r.client.Assistants().ModifyAssistant(state.Id.ValueString(), &aReq)
if err != nil {
resp.Diagnostics.AddError("OpenAI Client Error", fmt.Sprintf("Unable to modify assistant, got error: %s", err))
return
Expand Down

0 comments on commit a32166f

Please sign in to comment.