Skip to content

feat: add coder_task data source - #460

Merged
johnstcn merged 6 commits into
mainfrom
cj/coder_ai_task_prompt_datasource
Nov 4, 2025
Merged

johnstcn merged 6 commits into
mainfrom
cj/coder_ai_task_prompt_datasource

Conversation

@johnstcn

@johnstcn johnstcn commented Nov 3, 2025 •

Copy link
Copy Markdown
Member

Terraform will tolerate a certain amount of self-reference, but this changes when using count.

For example, the below is accepted

resource "coder_ai_task" "task" {
  app_id = module.agent.task_app_id
}

module "agent" {
  source = "..."
  prompt = coder_ai_task.task.prompt
}

Whereas this outputs a cycle error:

data "coder_workspace" "me" {}

resource "coder_ai_task" "task" {
  count = data.coder_workspace.me.start_count
  app_id = module.agent[count.index].task_app_id
}

module "agent" {
  count = data.coder_workspace.me.start_count
  source = "..."
  prompt = coder_ai_task.task[count.index].prompt
}

After some cursory searching, I didn't find much more information on this apart from this post.

Adding a data source is not too big a deal as the required environment variables are already present.

With this additional data source, the above example becomes:

data "coder_workspace" "me" {}
data "coder_task" "me" {}

resource "coder_ai_task" "task" {
  count = data.coder_workspace.me.start_count
  app_id = module.agent[count.index].task_app_id
}

module "agent" {
  count = data.coder_workspace.me.start_count
  source = "..."
  prompt = data.coder_task.me.prompt
}

NB: I explicitly named this coder_task to sidestep this check in Coder. I'm open to alternative names, but it can't be coder_ai_task.

See coder/coder#20416 for what this looks like in practice.

@johnstcn johnstcn changed the title feat: add coder_ai_task_prompt data source feat: add coder_task data source Nov 4, 2025
Comment thread provider/script_test.go
Comment on lines +134 to +137
name string
cronExpr string
expectWarnings bool
expectErrors bool

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by go fmt

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestions but otherwise 👍🏻

Comment thread provider/ai_task.go Resolved
Comment thread provider/ai_task.go Resolved
Comment thread provider/ai_task.go
"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.",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we set optional true, is that possible for computed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should according to the documentation for Computed:

If Required and Optional are both false, the attribute will be considered "read only" for the practitioner, with only the provider able to set its value.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah TIL, I had assumed computed already meant read-only.

Comment thread provider/ai_task_test.go Resolved
@johnstcn
johnstcn merged commit 5fe8d85 into main Nov 4, 2025
@johnstcn
johnstcn deleted the cj/coder_ai_task_prompt_datasource branch November 4, 2025 10:20
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants