Open
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
This is likely a case where we need to improve docs/error message.
There's a strange indexing error that gets thrown when the coder_agent
is assigned a count
and must be referenced with a tuple, but a module referencing it does contain a count
attribute.
With the following agent and module definition...
resource "coder_agent" "dev" {
count = data.coder_workspace.me.start_count
arch = "amd64"
auth = "token"
...
}
module "claude-code" {
source = "registry.coder.com/modules/claude-code/coder"
version = "1.0.31"
agent_id = coder_agent.dev[0].id
folder = "/home/coder"
install_claude_code = true
claude_code_version = "latest"
}
Terraform throws the following error:
Error: Invalid index
on main.tf line 339, in module "claude-code":
339: agent_id = coder_agent.dev[0].id
├────────────────
│ coder_agent.dev is empty tuple
The given key does not identify an element in this collection value: the collection has no elements.
Unless you specify count
in the module, then no error is thrown:
module "claude-code" {
count = data.coder_workspace.me.start_count
source = "registry.coder.com/modules/claude-code/coder"
version = "1.0.31"
agent_id = coder_agent.dev[0].id
folder = "/home/coder"
install_claude_code = true
claude_code_version = "latest"
}
Relevant Log Output
Expected Behavior
I did not realize that we had to define the count, so this may be a discoverability issue.
Steps to Reproduce
- Define
coder_agent
withcount = data.workspace.<me>.start_count
- Define module that requires `agent_id = coder_agent.[0].id
- Build
- Add
count = data.workspace.<me>.start_count
to module to resolve.
Environment
- Host OS: linux
- Coder version: v2.21.0