Description
At present, there is no good way to extract the agent name from Terraform and use it within the template. This is relevant for coder_app
's or anything else that wishes to create a working link to the workspace (agent) in a multi-agent environment.
Typically users have been able to use either <agent>.<workspace>
or <workspace>.<agent>
, and this will resolve to the correct agent when there is only one.
In Coder Desktop for example, using multiple agents means the FQDN becomes <agent>.<workspace>.me.coder
or <agent>.<workspace>.<username>.coder
and the short version <agent>.<workspace>
no longer works.
This is problematic especially in Coder modules as they cannot create URLs for the apps without asking the user to provide the agent name which can only be represented via a static sting in terraform. Resource names cannot be inspected which is where the name comes from.
Requirements:
- The user doesn't need to hard-code a string value for the agent name when
- Using coder modules
- Writing
coder_app
s
- (Optional, but ideal) the user only needs to provide the
agent_id
that is currently already being provided - (Optional) provide a FQDN like
<agent>.<workspace>.<owner>.coder
to access the agent
The optional requirement could perhaps be achieved via some form of new data on the coder_workspace
data source so that a lookup can be performed:
coder_workspace.me.agents[var.agent_id].name
Open to ideas on how and where to solve this.
There also exists a precedent for using fake environment variables and the product supports replacements of $SESSION_TOKEN
for coder_app
URLs, this is one potential avenue to achieve the same, albeit not ideal.