terraform-provider-coder icon indicating copy to clipboard operation
terraform-provider-coder copied to clipboard

Conflict when adding `coder_metadata` with duplicate `resource_id`s

Open matifali opened this issue 1 year ago • 7 comments

Problem Description

  1. While adding coder_metadata blocks inside a module we need to pass the resource_id to link the metadata to. The issue arises when the resource_id of the instance is linked to an existing coder_metadata block in the main template, which causes a conflict and the template fails to build.

  2. Attempting to use an alternative identifier, such as agent_id, doesn't show metadata on the workspace page.

Steps to Reproduce

  1. Add a coder_metadata block to a module and link it to the resource_id of an instance.
  2. Add another coder_metadata block in the main template referencing the same resource_id.
  3. Observe the conflict in the failed build.
  4. 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 same resource_id. One possible solution is to merge and append the new item entries when we detect a conflict in resource_id.
  • Investigate why the agent_id does not work with coder_metadata.

[!Note] We did allow adding multiple coder_metadata with the same resource_id. See coder/coder#6517.

matifali avatar Nov 19 '24 18:11 matifali

I was able to use your build with success. It was with the Kubernetes (Devcontainer) template (fixing the module code-server of course) and switching the locals to use the image:

locals {
  #devcontainer_builder_image = data.coder_parameter.devcontainer_builder.value
  devcontainer_builder_image = "ghcr.io/derektamsen/envbuilder-preview:latest"
}

mcharris avatar Sep 26 '25 14:09 mcharris

Not sure why this hasn't been reviewed and merge. Includes tests and valid code. Nice work!

mcharris avatar Sep 26 '25 14:09 mcharris