Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: addenabled computed field tocoder_ai_task#451

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
DanielleMaywood merged 1 commit intomainfromdanielle/tasks/enabled-field
Oct 31, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsdocs/resources/ai_task.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,6 +22,7 @@ Use this resource to define Coder tasks.

### Read-Only

- `enabled` (Boolean) True when executing in a Coder Task context, false when in a Coder Workspace context
- `id` (String) A unique identifier for this resource.
- `prompt` (String) The prompt text provided to the task by Coder.

Expand Down
9 changes: 5 additions & 4 deletionsintegration/coder-ai-task/main.tf
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -41,10 +41,11 @@ resource "coder_ai_task" "task" {
locals {
# NOTE: these must all be strings in the output
output = {
"ai_task.id" = coder_ai_task.task.id
"ai_task.app_id" = coder_ai_task.task.app_id
"ai_task.prompt" = coder_ai_task.task.prompt
"app.id" = coder_app.ai_interface.id
"ai_task.id" = coder_ai_task.task.id
"ai_task.app_id" = coder_ai_task.task.app_id
"ai_task.prompt" = coder_ai_task.task.prompt
"ai_task.enabled" = tostring(coder_ai_task.task.enabled)
"app.id" = coder_app.ai_interface.id
}
}

Expand Down
9 changes: 5 additions & 4 deletionsintegration/integration_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -215,10 +215,11 @@ func TestIntegration(t *testing.T) {
name: "coder-ai-task",
minVersion: "v2.26.0",
expectedOutput: map[string]string{
"ai_task.id": `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`,
"ai_task.prompt": "",
"ai_task.app_id": `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`,
"app.id": `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`,
"ai_task.id": `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`,
"ai_task.prompt": "",
"ai_task.app_id": `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`,
"ai_task.enabled": "false",
"app.id": `^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`,
},
},
} {
Expand Down
16 changes: 9 additions & 7 deletionsprovider/ai_task.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,15 +32,12 @@ func aiTaskResource() *schema.Resource {
CreateContext: func(c context.Context, resourceData *schema.ResourceData, i any) diag.Diagnostics {
var diags diag.Diagnostics

if idStr := os.Getenv("CODER_TASK_ID"); idStr != "" {
resourceData.SetId(idStr)
if id, err := uuid.Parse(os.Getenv("CODER_TASK_ID")); err == nil && id != uuid.Nil {
resourceData.SetId(id.String())
resourceData.Set("enabled", true)
} else {
resourceData.SetId(uuid.NewString())

diags = append(diags, diag.Diagnostic{
Severity: diag.Warning,
Summary: "`CODER_TASK_ID` should be set. If you are seeing this message, the version of the Coder Terraform provider you are using is likely too new for your current Coder version.",
})
resourceData.Set("enabled", false)
}

if prompt := os.Getenv("CODER_TASK_PROMPT"); prompt != "" {
Expand DownExpand Up@@ -110,6 +107,11 @@ func aiTaskResource() *schema.Resource {
ValidateFunc: validation.IsUUID,
ConflictsWith: []string{"sidebar_app"},
},
"enabled": {
Type: schema.TypeBool,
Description: "True when executing in a Coder Task context, false when in a Coder Workspace context",
Computed: true,
},
},
}
}
58 changes: 58 additions & 0 deletionsprovider/ai_task_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,62 @@ import (
"github.com/stretchr/testify/require"
)

func TestAITask_Enabled(t *testing.T) {
t.Run("EnabledWhenTask", func(t *testing.T) {
t.Setenv("CODER_TASK_ID", "7d8d4c2e-fb57-44f9-a183-22509819c2e7")

resource.Test(t, resource.TestCase{
ProviderFactories: coderFactory(),
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: `
provider "coder" {
}
resource "coder_ai_task" "test" {
app_id = "9a3ff7b4-4b3f-48c6-8d3a-a8118ac921fc"
}
`,
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)

require.Equal(t, "true", resource.Primary.Attributes["enabled"])

return nil
},
}},
})
})

t.Run("DisabledWhenWorkspace", func(t *testing.T) {
t.Setenv("CODER_TASK_ID", "")

resource.Test(t, resource.TestCase{
ProviderFactories: coderFactory(),
IsUnitTest: true,
Steps: []resource.TestStep{{
Config: `
provider "coder" {
}
resource "coder_ai_task" "test" {
app_id = "9a3ff7b4-4b3f-48c6-8d3a-a8118ac921fc"
}
`,
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)

require.Equal(t, "false", resource.Primary.Attributes["enabled"])

return nil
},
}},
})
})
}

func TestAITask(t *testing.T) {
t.Setenv("CODER_TASK_ID", "7d8d4c2e-fb57-44f9-a183-22509819c2e7")
t.Setenv("CODER_TASK_PROMPT", "some task prompt")
Expand All@@ -35,6 +91,7 @@ func TestAITask(t *testing.T) {
"id",
"prompt",
"app_id",
"enabled",
} {
value := resource.Primary.Attributes[key]
require.NotNil(t, value)
Expand DownExpand Up@@ -97,6 +154,7 @@ func TestAITask(t *testing.T) {
"id",
"prompt",
"app_id",
"enabled",
} {
value := resource.Primary.Attributes[key]
require.NotNil(t, value)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp