Description
Problem Description
-
While adding
coder_metadata
blocks inside a module we need to pass the resource_id to link the metadata to. The issue arises when theresource_id
of the instance is linked to an existingcoder_metadata
block in the main template, which causes a conflict and the template fails to build. -
Attempting to use an alternative identifier, such as
agent_id
, doesn't show metadata on the workspace page.
Steps to Reproduce
- Add a
coder_metadata
block to a module and link it to theresource_id
of an instance. - Add another
coder_metadata
block in the main template referencing the sameresource_id
. - Observe the conflict in the failed build.
- Attempt to use
agent_id
instead in the module and note the absence of display metadata.
Impact
- Limits the flexibility of the coder modules because of possible conflicts.
Next Steps
- Update the handling of
coder_metadata
to avoid conflicts between module-level and main template declarations when sharing the sameresource_id
. One possible solution is to merge and append the newitem
entries when we detect a conflict inresource_id
. - Investigate why the
agent_id
does not work withcoder_metadata
.
Note
We did allow adding multiple coder_metadata
with the same resource_id
. See coder/coder#6517.
Sub-issues
Sub-issues
- Manage this item control shift u
- Manage this item control shift u
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Conflict When Adding `coder_metadata` in Modules[/-][+]Conflict when adding `coder_metadata` with duplicate `resouce_id`s[/+]matifali commentedon Nov 20, 2024
Related: #306
ethanndickson commentedon Nov 20, 2024
The provisioner doesn't currently handle associating
coder_metadata
withcoder_*
resources, such as the agent. (1).All other Terraform resources are returned by the provisioner as containing a list of
Resource_Metadata
, which is populated using attachedcoder_metadata
resources. Once that list is populated, thosecoder_metadata
resources are discarded.The agent is not returned by the provisioner as it's own resource, similarly to the metadata, it's just a field on the attached resource.
You can see this if you

GET
a workspace and view the raw json, this is thedocker_container
resource on my dogfood workspace, for example:So to resolve this issue, I'd propose just two changes:
If a
coder_metadata
resource would be attached to acoder_agent
resource (via the output ofterraform graph
), then we should instead attempt to convert that metadata to static values that would be returned byhttps://dev.coder.com/api/v2/workspaceagents/{id}/watch-metadata
. This would require minimal changes to the provisioner, and (presumably) no changes to the frontend. The staticcoder_metadata
items would show up alongside the dynamic metadata on the agent (which is defined withinmetadata
blocks withincoder_agent
).As you said, If multiple
coder_metadata
resources would be attached to a single non-coder_*
resource, then I agree that we should merge/append theitem
s, instead of simply returning an error. Again, this would only require provisioner changes, and should be a pretty trivial implementation.matifali commentedon Nov 20, 2024
I don't think we should merge the dynamic
metadata
of thecoder_agent
and the staticcoder_metadata
linked to the samecoder_agent
as It would cause confusion for the user. If we want to do this, we should either,display them on a separate row/section (requires changes in the frontend and also would be different from generalcoder_metadata
behavior attached to other noncoder_*
resources).coder_metadata
gets displayed.ethanndickson commentedon Nov 20, 2024
1: Sounds like a good solution, just a fair bit more work.
2: This would effectively be merging the agent's static metadata with the first resource of the workspace, which would be equally confusing as merging it with the dynamic agent metadata.
EDIT: I don't think 1 is the right move, it would mean we have agent metadata in the UI in two different places, depending on whether it's set in the template, or retrieved dynamically via a command.
matifali commentedon Nov 20, 2024
I don't mean we merge the
coder_metadata
assigned to different resources but merge if multiplecoder_metadata
are linked to a single resource. Consider the example below,We should display a single coder_metadata section and merge the
item
from bothcoder_metadata
resources as they are both linked with the sameresource.aws_instance.dev
resource. We may still get conflicts if theitem
keys are not unique.What do you think about it @bpmct?
ethanndickson commentedon Nov 20, 2024
Oh I see what you mean, yeah. That's what you suggested originally, I definitely agree that's a good solution. but that doesn't address where
coder_metadata
attached to acoder_agent
should go.matifali commentedon Nov 20, 2024
Yes, maybe we can narrow the scope so as not to support the
coder_agent
for now, just update our modules to pass another resource_id as input, and attach all metadata to that resource from within the modules. This would only need the ability to link multiplecoder_metadata
to a single resource and merge the items.