- Notifications
You must be signed in to change notification settings - Fork24
feat: addcoder_ai_task resource#413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletionsdocs/resources/ai_task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| # generated by https://github.com/hashicorp/terraform-plugin-docs | ||
| page_title: "coder_ai_task Resource - terraform-provider-coder" | ||
| subcategory: "" | ||
| description: |- | ||
| Use this resource to define Coder tasks. | ||
| --- | ||
| # coder_ai_task (Resource) | ||
| Use this resource to define Coder tasks. | ||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
| ### Required | ||
| - `sidebar_app` (Block Set, Min: 1, Max: 1) The coder_app to display in the sidebar. Usually a chat interface with the AI agent running in the workspace, like https://github.com/coder/agentapi. (see [below for nested schema](#nestedblock--sidebar_app)) | ||
| ### Read-Only | ||
| - `id` (String) A unique identifier for this resource. | ||
| <a id="nestedblock--sidebar_app"></a> | ||
| ### Nested Schema for `sidebar_app` | ||
| Required: | ||
| - `id` (String) A reference to an existing `coder_app` resource in your template. |
61 changes: 61 additions & 0 deletionsprovider/ai_task.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package provider | ||
| import ( | ||
| "context" | ||
| "github.com/google/uuid" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
| ) | ||
| type AITask struct { | ||
| ID string `mapstructure:"id"` | ||
| SidebarApp []AITaskSidebarApp `mapstructure:"sidebar_app"` | ||
| } | ||
| type AITaskSidebarApp struct { | ||
| ID string `mapstructure:"id"` | ||
| } | ||
| // TaskPromptParameterName is the name of the parameter which is *required* to be defined when a coder_ai_task is used. | ||
| const TaskPromptParameterName = "AI Prompt" | ||
| func aiTask() *schema.Resource { | ||
| return &schema.Resource{ | ||
| SchemaVersion: 1, | ||
| Description: "Use this resource to define Coder tasks.", | ||
| CreateContext: func(c context.Context, resourceData *schema.ResourceData, i any) diag.Diagnostics { | ||
| resourceData.SetId(uuid.NewString()) | ||
| return nil | ||
| }, | ||
| ReadContext: schema.NoopContext, | ||
| DeleteContext: schema.NoopContext, | ||
| Schema: map[string]*schema.Schema{ | ||
| "id": { | ||
| Type: schema.TypeString, | ||
| Description: "A unique identifier for this resource.", | ||
| Computed: true, | ||
| }, | ||
| "sidebar_app": { | ||
| Type: schema.TypeSet, | ||
| Description: "The coder_app to display in the sidebar. Usually a chat interface with the AI agent running in the workspace, like https://github.com/coder/agentapi.", | ||
| ForceNew: true, | ||
| Required: true, | ||
| MaxItems: 1, | ||
| Elem: &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "id": { | ||
| Type: schema.TypeString, | ||
| Description: "A reference to an existing `coder_app` resource in your template.", | ||
| Required: true, | ||
| ForceNew: true, | ||
| ValidateFunc: validation.IsUUID, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| } |
82 changes: 82 additions & 0 deletionsprovider/ai_task_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package provider_test | ||
| import ( | ||
| "regexp" | ||
| "testing" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
| func TestAITask(t *testing.T) { | ||
| t.Parallel() | ||
| t.Run("OK", func(t *testing.T) { | ||
| t.Parallel() | ||
| resource.Test(t, resource.TestCase{ | ||
| ProviderFactories: coderFactory(), | ||
| IsUnitTest: true, | ||
| Steps: []resource.TestStep{{ | ||
| Config: ` | ||
| provider "coder" { | ||
| } | ||
| resource "coder_agent" "dev" { | ||
| os = "linux" | ||
| arch = "amd64" | ||
| } | ||
| resource "coder_app" "code-server" { | ||
| agent_id = coder_agent.dev.id | ||
| slug = "code-server" | ||
| display_name = "code-server" | ||
| icon = "builtin:vim" | ||
| url = "http://localhost:13337" | ||
| open_in = "slim-window" | ||
| } | ||
| resource "coder_ai_task" "test" { | ||
| sidebar_app { | ||
| id = coder_app.code-server.id | ||
| } | ||
| } | ||
| `, | ||
| Check: func(state *terraform.State) error { | ||
| require.Len(t, state.Modules, 1) | ||
| resource := state.Modules[0].Resources["coder_ai_task.test"] | ||
| require.NotNil(t, resource) | ||
| for _, key := range []string{ | ||
| "id", | ||
| "sidebar_app.#", | ||
| } { | ||
| value := resource.Primary.Attributes[key] | ||
| require.NotNil(t, value) | ||
| require.Greater(t, len(value), 0) | ||
| } | ||
| require.Equal(t, "1", resource.Primary.Attributes["sidebar_app.#"]) | ||
| return nil | ||
| }, | ||
| }}, | ||
| }) | ||
| }) | ||
| t.Run("InvalidSidebarAppID", func(t *testing.T) { | ||
| t.Parallel() | ||
| resource.Test(t, resource.TestCase{ | ||
| ProviderFactories: coderFactory(), | ||
| IsUnitTest: true, | ||
| Steps: []resource.TestStep{{ | ||
| Config: ` | ||
| provider "coder" { | ||
| } | ||
| resource "coder_ai_task" "test" { | ||
| sidebar_app { | ||
| id = "not-a-uuid" | ||
| } | ||
| } | ||
| `, | ||
| ExpectError: regexp.MustCompile(`expected "sidebar_app.0.id" to be a valid UUID`), | ||
| }}, | ||
| }) | ||
| }) | ||
| } |
1 change: 1 addition & 0 deletionsprovider/provider.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.