- Notifications
You must be signed in to change notification settings - Fork24
feat: add coder_task data source#460
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
Changes fromall commits
37908cf51684f4a27420c1983ed011bc9949ef5524File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --- | ||
| # generated by https://github.com/hashicorp/terraform-plugin-docs | ||
| page_title: "coder_task Data Source - terraform-provider-coder" | ||
| subcategory: "" | ||
| description: |- | ||
| Use this data source to read information about Coder Tasks. | ||
| --- | ||
| # coder_task (Data Source) | ||
| Use this data source to read information about Coder Tasks. | ||
| ## Example Usage | ||
| ```terraform | ||
| provider "coder" {} | ||
| data "coder_workspace" "me" {} | ||
| data "coder_task" "me" {} | ||
| resource "coder_ai_task" "task" { | ||
| count = data.coder_task.me.enabled ? data.coder_workspace.me.start_count : 0 | ||
| app_id = module.example-agent.task_app_id | ||
| } | ||
| module "example-agent" { | ||
| count = data.coder_task.me.enabled ? data.coder_workspace.me.start_count : 0 | ||
| prompt = data.coder_ai_task.me.prompt | ||
| } | ||
| ``` | ||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
| ### Read-Only | ||
| - `enabled` (Boolean) True when executing in a Coder Task context, false when in a Coder Workspace context. | ||
| -> The `enabled` field is only populated in Coder v2.28 and later. | ||
| - `id` (String) The UUID of the task, if executing in a Coder Task context. Empty in a Coder Workspace context. | ||
| - `prompt` (String) The prompt text provided to the task by Coder, if executing in a Coder Task context. Empty in a Coder Workspace context. | ||
| -> The `prompt` field is only populated in Coder v2.28 and later. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| provider"coder" {} | ||
| data"coder_workspace""me" {} | ||
| data"coder_task""me" {} | ||
| resource"coder_ai_task""task" { | ||
| count=data.coder_task.me.enabled? data.coder_workspace.me.start_count:0 | ||
| app_id=module.example-agent.task_app_id | ||
| } | ||
| module"example-agent" { | ||
| count=data.coder_task.me.enabled? data.coder_workspace.me.start_count:0 | ||
| prompt=data.coder_ai_task.me.prompt | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -115,3 +115,43 @@ func aiTaskResource() *schema.Resource { | ||
| }, | ||
| } | ||
| } | ||
| func taskDatasource() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Description: "Use this data source to read information about Coder Tasks.", | ||
| ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
| diags := diag.Diagnostics{} | ||
| idStr := os.Getenv("CODER_TASK_ID") | ||
| if idStr == "" || idStr == uuid.Nil.String() { | ||
| rd.SetId(uuid.NewString()) | ||
| _ = rd.Set("enabled", false) | ||
| } else if _, err := uuid.Parse(idStr); err == nil { | ||
| rd.SetId(idStr) | ||
| _ = rd.Set("enabled", true) | ||
| } else { // invalid UUID | ||
| diags = append(diags, errorAsDiagnostics(err)...) | ||
| } | ||
| _ = rd.Set("prompt", os.Getenv("CODER_TASK_PROMPT")) | ||
| return diags | ||
| }, | ||
| Schema: map[string]*schema.Schema{ | ||
| "id": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The UUID of the task, if executing in a Coder Task context. Empty in a Coder Workspace context.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Should we set optional true, is that possible for computed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't think we should according to the documentation for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ah TIL, I had assumed computed already meant read-only. | ||
| }, | ||
| "prompt": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| Description: "The prompt text provided to the task by Coder, if executing in a Coder Task context. Empty in a Coder Workspace context.\n\n -> The `prompt` field is only populated in Coder v2.28 and later.", | ||
| }, | ||
| "enabled": { | ||
| Type: schema.TypeBool, | ||
| Computed: true, | ||
| Description: "True when executing in a Coder Task context, false when in a Coder Workspace context.\n\n -> The `enabled` field is only populated in Coder v2.28 and later.", | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -131,10 +131,10 @@ func TestValidateCronExpression(t *testing.T) { | ||
| t.Parallel() | ||
| tests:= []struct { | ||
| namestring | ||
| cronExprstring | ||
| expectWarningsbool | ||
| expectErrorsbool | ||
Comment on lines +134 to +137 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. drive-by | ||
| warningContainsstring | ||
| }{ | ||
| { | ||