From 72d0ca65ca848cd37f4bcf38f239110349ee3c30 Mon Sep 17 00:00:00 2001 From: Anthony Sterling Date: Mon, 2 Jun 2025 11:08:05 +0000 Subject: [PATCH 1/3] feat: allow configuration of output_modality --- go.mod | 3 ++- go.sum | 2 ++ internal/provider/task_resource.go | 11 +++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index d426a37..3499db7 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,9 @@ go 1.23.4 require ( github.com/benbjohnson/clock v1.3.5 github.com/hashicorp/terraform-plugin-framework v1.14.1 + github.com/hashicorp/terraform-plugin-framework-validators v0.18.0 github.com/hashicorp/terraform-plugin-go v0.26.0 + github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-testing v1.12.0 github.com/stretchr/testify v1.10.0 ) @@ -17,7 +19,6 @@ require ( github.com/hashicorp/go-hclog v1.6.3 // indirect github.com/hashicorp/go-plugin v1.6.2 // indirect github.com/hashicorp/go-uuid v1.0.3 // indirect - github.com/hashicorp/terraform-plugin-log v0.9.0 // indirect github.com/hashicorp/terraform-registry-address v0.2.4 // indirect github.com/hashicorp/terraform-svchost v0.1.1 // indirect github.com/hashicorp/yamux v0.1.1 // indirect diff --git a/go.sum b/go.sum index 4d18463..b60600a 100644 --- a/go.sum +++ b/go.sum @@ -58,6 +58,8 @@ github.com/hashicorp/terraform-json v0.24.0 h1:rUiyF+x1kYawXeRth6fKFm/MdfBS6+lW4 github.com/hashicorp/terraform-json v0.24.0/go.mod h1:Nfj5ubo9xbu9uiAoZVBsNOjvNKB66Oyrvtit74kC7ow= github.com/hashicorp/terraform-plugin-framework v1.14.1 h1:jaT1yvU/kEKEsxnbrn4ZHlgcxyIfjvZ41BLdlLk52fY= github.com/hashicorp/terraform-plugin-framework v1.14.1/go.mod h1:xNUKmvTs6ldbwTuId5euAtg37dTxuyj3LHS3uj7BHQ4= +github.com/hashicorp/terraform-plugin-framework-validators v0.18.0 h1:OQnlOt98ua//rCw+QhBbSqfW3QbwtVrcdWeQN5gI3Hw= +github.com/hashicorp/terraform-plugin-framework-validators v0.18.0/go.mod h1:lZvZvagw5hsJwuY7mAY6KUz45/U6fiDR0CzQAwWD0CA= github.com/hashicorp/terraform-plugin-go v0.26.0 h1:cuIzCv4qwigug3OS7iKhpGAbZTiypAfFQmw8aE65O2M= github.com/hashicorp/terraform-plugin-go v0.26.0/go.mod h1:+CXjuLDiFgqR+GcrM5a2E2Kal5t5q2jb0E3D57tTdNY= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= diff --git a/internal/provider/task_resource.go b/internal/provider/task_resource.go index 3d28496..3827aa4 100644 --- a/internal/provider/task_resource.go +++ b/internal/provider/task_resource.go @@ -10,12 +10,15 @@ import ( "terraform-provider-tasks/internal/sdk" entitites "terraform-provider-tasks/internal/sdk/entities" + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" + "github.com/hashicorp/terraform-plugin-framework/schema/validator" "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -166,6 +169,14 @@ func (r *TaskResource) Schema(ctx context.Context, req resource.SchemaRequest, r Required: true, ElementType: types.StringType, }, + "output_modality": schema.StringAttribute{ + Optional: true, + Description: "Specifies the output modality of the task. Can be 'json' or 'image'", + Default: stringdefault.StaticString("json"), + Validators: []validator.String{ + stringvalidator.OneOf("json", "image"), + }, + }, }, Blocks: map[string]schema.Block{ "input_processors": schema.SingleNestedBlock{ From 765ac09a8cdc97bd6dd3681c7f6180998adce916 Mon Sep 17 00:00:00 2001 From: anthonysterling Date: Mon, 2 Jun 2025 12:36:52 +0000 Subject: [PATCH 2/3] feat: update model for output modality --- internal/provider/task_resource.go | 4 +++- internal/sdk/entities/task.go | 1 + internal/sdk/requests.go | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/provider/task_resource.go b/internal/provider/task_resource.go index 3827aa4..e664d8f 100644 --- a/internal/provider/task_resource.go +++ b/internal/provider/task_resource.go @@ -170,7 +170,7 @@ func (r *TaskResource) Schema(ctx context.Context, req resource.SchemaRequest, r ElementType: types.StringType, }, "output_modality": schema.StringAttribute{ - Optional: true, + Required: true, Description: "Specifies the output modality of the task. Can be 'json' or 'image'", Default: stringdefault.StaticString("json"), Validators: []validator.String{ @@ -242,6 +242,7 @@ func (r *TaskResource) Create(ctx context.Context, req resource.CreateRequest, r in.Enabled = data.Enabled.ValueBool() in.Public = data.Public.ValueBool() in.ImageRequired = data.ImageRequired.ValueBool() + in.OutputModality = data.OutputModality.ValueString() for k, v := range data.OutputFormat { in.OutputFormat[k] = v.ValueString() @@ -307,6 +308,7 @@ func (r *TaskResource) Update(ctx context.Context, req resource.UpdateRequest, r in.Enabled = data.Enabled.ValueBool() in.Public = data.Public.ValueBool() in.ImageRequired = data.ImageRequired.ValueBool() + in.OutputModality = data.OutputModality.ValueString() for k, v := range data.OutputFormat { in.OutputFormat[k] = v.ValueString() diff --git a/internal/sdk/entities/task.go b/internal/sdk/entities/task.go index cb4f4b0..618ff5b 100644 --- a/internal/sdk/entities/task.go +++ b/internal/sdk/entities/task.go @@ -46,6 +46,7 @@ type Revision struct { Active bool `json:"active"` RAG RAG `json:"rag"` InputProcessors *[]InputProcessor `json:"input_processors"` + OutputModality string `json:"output_modality"` } func (r *Revision) HasInputProcessors() bool { diff --git a/internal/sdk/requests.go b/internal/sdk/requests.go index 0af8963..2cff4d2 100644 --- a/internal/sdk/requests.go +++ b/internal/sdk/requests.go @@ -15,6 +15,7 @@ type CreateTaskRequest struct { LLMModelID string `json:"llm_model_id"` Name string `json:"name"` OutputFormat map[string]string `json:"output_format"` + OutputModality string `json:"output_modality"` Public bool `json:"public"` SystemPrompt string `json:"system_prompt"` UserPrompt string `json:"user_prompt"` @@ -35,6 +36,7 @@ type UpdateTaskRequest struct { LLMModelID string `json:"llm_model_id"` Name string `json:"name"` OutputFormat map[string]string `json:"output_format"` + OutputModality string `json:"output_modality"` Public bool `json:"public"` SystemPrompt string `json:"system_prompt"` UserPrompt string `json:"user_prompt"` From 2a9cb0326ad877dcfd7f37080dabf444aecaf44f Mon Sep 17 00:00:00 2001 From: anthonysterling Date: Mon, 2 Jun 2025 13:40:32 +0100 Subject: [PATCH 3/3] update docs --- docs/resources/task.md | 1 + internal/provider/task_resource.go | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/resources/task.md b/docs/resources/task.md index a60a16f..a79bc67 100644 --- a/docs/resources/task.md +++ b/docs/resources/task.md @@ -29,6 +29,7 @@ Task resource - `description` (String) A description of the Task. - `image_required` (Boolean) - `input_processors` (Block, Optional) (see [below for nested schema](#nestedblock--input_processors)) +- `output_modality` (String) Specifies the output modality of the task. Can be 'json' or 'image' - `public` (Boolean) ### Read-Only diff --git a/internal/provider/task_resource.go b/internal/provider/task_resource.go index e664d8f..3ec79a4 100644 --- a/internal/provider/task_resource.go +++ b/internal/provider/task_resource.go @@ -53,13 +53,13 @@ type TaskResourceModel struct { Public types.Bool `tfsdk:"public"` Description types.String `tfsdk:"description"` - SystemPrompt types.String `tfsdk:"system_prompt"` - UserPrompt types.String `tfsdk:"user_prompt"` - LLMModelID types.String `tfsdk:"llm_model_id"` - ImageRequired types.Bool `tfsdk:"image_required"` - OutputFormat map[string]types.String `tfsdk:"output_format"` - - InputProcessors *InputProcessorsModel `tfsdk:"input_processors"` + SystemPrompt types.String `tfsdk:"system_prompt"` + UserPrompt types.String `tfsdk:"user_prompt"` + LLMModelID types.String `tfsdk:"llm_model_id"` + ImageRequired types.Bool `tfsdk:"image_required"` + OutputFormat map[string]types.String `tfsdk:"output_format"` + OutputModality types.String `tfsdk:"output_modality"` + InputProcessors *InputProcessorsModel `tfsdk:"input_processors"` ActiveRevisionID types.String `tfsdk:"active_revision_id"` } @@ -170,9 +170,10 @@ func (r *TaskResource) Schema(ctx context.Context, req resource.SchemaRequest, r ElementType: types.StringType, }, "output_modality": schema.StringAttribute{ - Required: true, + Optional: true, Description: "Specifies the output modality of the task. Can be 'json' or 'image'", Default: stringdefault.StaticString("json"), + Computed: true, Validators: []validator.String{ stringvalidator.OneOf("json", "image"), },