Coder Workspace Metadata Display

I am having trouble displaying the Coder Metadata shown in the blue box. I am using the latest version of coder. My goal is to display a value that is in locals
locals {
workspace_id = "${data.coder_workspace_owner.me.name}-${data.coder_workspace.me.name}-${local.short_workspace_id}"
}

resource "coder_metadata" "workspace_info" {
resource_id = coder_agent.main.id
item {
key = "WorkspaceID"
value = local.workspace_id
}
}
locals {
workspace_id = "${data.coder_workspace_owner.me.name}-${data.coder_workspace.me.name}-${local.short_workspace_id}"
}

resource "coder_metadata" "workspace_info" {
resource_id = coder_agent.main.id
item {
key = "WorkspaceID"
value = local.workspace_id
}
}
Docs: https://coder.com/docs/admin/templates/extending-templates/resource-metadata
Coder
Resource Metadata | Coder Docs
Display resource state in the workspace dashboard
No description
Solution:
Thank you! With your help I was able to show metadata in the correct location. ``` locals { workspace_full_name = "${data.coder_workspace_owner.me.name}-${data.coder_workspace.me.name}-${local.short_workspace_id}" }...
No description
Jump to solution
9 Replies
Phorcys
Phorcys2w ago
@Jason Overmier sorry about the delay, were you able to figure it out?
Jason Overmier
Jason OvermierOP2w ago
No I haven't. Spent a couple hours and gave up. I assume it is a pretty simple fix if it isn't a bug
Ethan
Ethan2w ago
try setting the resource_id on the coder_metadata resource to whatever terraform resource is first in this list:
No description
Ethan
Ethan2w ago
(you'll need to click that symbol in the top left to get this list to appear) if you click through those resources you should see the metadata on one
Jason Overmier
Jason OvermierOP2w ago
I found the resource that shows it. How can it be configure to show up on the first resource (coder)?
No description
No description
Ethan
Ethan2w ago
Just by changing the resource_id on the coder_metadata to kubernetes_deployment.coder.id instead of coder_agent.main coder_metadata can only be associated to non-coder_* resources, and since you've associated it to the agent, it's picking what it thinks is the next best resource if you want to add metadata specifically to the agent, that's done in metadata blocks on the coder_agent (the green text metadata in the agent UI) In fairness, we have quite a few example templates that set resource_id to an agent ID, and but whether or not it gets you the intended result depends on the template. In your case it unfortunately doesn't 🙁
Solution
Jason Overmier
Thank you! With your help I was able to show metadata in the correct location.
locals {
workspace_full_name = "${data.coder_workspace_owner.me.name}-${data.coder_workspace.me.name}-${local.short_workspace_id}"
}


# Clone Information Metadata
resource "coder_metadata" "workspace_full_name" {
count = data.coder_workspace.me.start_count
resource_id = kubernetes_deployment.coder[0].id
item {
key = "Workspace Full Name"
value = local.workspace_full_name
}
}
locals {
workspace_full_name = "${data.coder_workspace_owner.me.name}-${data.coder_workspace.me.name}-${local.short_workspace_id}"
}


# Clone Information Metadata
resource "coder_metadata" "workspace_full_name" {
count = data.coder_workspace.me.start_count
resource_id = kubernetes_deployment.coder[0].id
item {
key = "Workspace Full Name"
value = local.workspace_full_name
}
}
No description
Jason Overmier
Jason OvermierOP2w ago
Validation wouldn't pass without adding in the count
Codercord
Codercord4d ago
@Phorcys closed the thread.

Did you find this page helpful?