-
Notifications
You must be signed in to change notification settings - Fork 24
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
37908cf
51684f4
a27420c
1983ed0
11bc994
9ef5524
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| # 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. | ||
|
|
||
|
|
||
|
|
||
| <!-- schema generated by tfplugindocs --> | ||
| ## Schema | ||
|
|
||
| ### Read-Only | ||
|
|
||
| - `enabled` (Boolean) True when executing in a Coder Task context, false when in a Coder Workspace context. | ||
|
|
||
| ->This 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. | ||
|
|
||
| ->This field is only populated in Coder v2.28 and later. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,3 +115,43 @@ func aiTaskResource() *schema.Resource { | |
| }, | ||
| } | ||
| } | ||
|
|
||
| func aiTaskDatasource() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Description: "Use this data source to read information about Coder tasks.", | ||
johnstcn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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->This 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->This 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 { | ||
| name string | ||
| cronExpr string | ||
| expectWarnings bool | ||
| expectErrors bool | ||
| name string | ||
| cronExpr string | ||
| expectWarnings bool | ||
| expectErrors bool | ||
|
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 |
||
| warningContains string | ||
| }{ | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.