Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: use resource_id directly for coder_metadata association#18300

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
sreya wants to merge9 commits intomainfromjon/resourcemetadata

Conversation

@sreya
Copy link
Collaborator

@sreyasreya commentedJun 10, 2025
edited by ethanndickson
Loading

Previously, coder_metadata resources would associate with the wrong Terraform resource because the implementation relied on graph traversal instead of using the explicit resource_id attribute.

This fix:

  • Builds a map from resource IDs to their labels for direct lookup
  • Uses the resource_id attribute to find the target resource directly
  • Falls back to graph traversal only if resource_id lookup fails
  • Adds logging when resource_id is not found in the state

This ensures that metadata is correctly associated with the intended resource, even when there are complex dependencies in the Terraform configuration.

Fixes the issue where coder_metadata would incorrectly associate with resources it references in its values rather than the resource specified in resource_id.

Closes#18301
Closescoder/terraform-provider-coder#306

matifali reacted with rocket emoji
@sreyasreyaforce-pushed thejon/resourcemetadata branch from439f812 to558c1ebCompareJune 10, 2025 03:41
@github-actionsgithub-actionsbot added the staleThis issue is like stale bread. labelJun 20, 2025
@sreyasreya reopened thisJun 23, 2025
@github-actionsgithub-actionsbot removed the staleThis issue is like stale bread. labelJun 24, 2025
@github-actionsgithub-actionsbot added the staleThis issue is like stale bread. labelJul 1, 2025
@ThomasK33ThomasK33 reopened thisAug 8, 2025
@ThomasK33ThomasK33 assignedThomasK33 and unassignedsreyaAug 8, 2025
@ThomasK33ThomasK33 marked this pull request as ready for reviewAugust 8, 2025 10:41
@github-actionsgithub-actionsbot removed the staleThis issue is like stale bread. labelAug 9, 2025
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think we are at a point where it would make sense to start breaking upConvertState. This metadata association piece seems like a good candidate to start with and have individual unit tests around.

Comment on lines +706 to +710
case0:
// If we couldn't find by ID, fall back to graph traversal
logger.Warn(ctx,"coder_metadata resource_id not found, falling back to graph traversal",
slog.F("resource_id",attrs.ResourceID),
slog.F("metadata_address",resource.Address))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As far as I can tell, this warn log will just end up in the server log and won't be especially visible to template authors.

I can see an argument for erroring out here, but the larger argument against is that it would most likely break existing templates. How do we feel about this?

Comment on lines +714 to +719
default:
// Multiple resources with same ID - this creates ambiguity
logger.Warn(ctx,"multiple resources found with same resource_id, falling back to graph traversal",
slog.F("resource_id",attrs.ResourceID),
slog.F("metadata_address",resource.Address),
slog.F("matching_labels",foundLabels))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Again, I can see an argument for erroring here to surface the misconfiguration but worry about the potential for breaking existing templates.

continue
}
}
ifattachedResource==nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In what situation would we encounter this? It's not covered in existing or new tests.

resourceLabel:=convertAddressToLabel(resource.Address)

varattachedNode*gographviz.Node
for_,node:=rangegraph.Nodes.Lookup {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

At this stage, it would make sense to extract the "metadata association" piece out and test it separately.

resource"null_resource""example" {}

resource"coder_metadata""example" {
resource_id="non-existent-id"
Copy link
Member

@ethanndicksonethanndicksonAug 13, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should have another test to check that it falls back to graph traversal when theresource_id is set tocoder_agent.whatever.id. I've seen that pattern in many customer templates in the past.

@spikecurtis
Copy link
Contributor

Is there an issue that describes the problem this is intending to solve?

It worries me that we're using resource IDs to identify the resource the metadata refers to when resource IDs are not unique. I think it would be better to deprecate the resource ID and instead use something unique like (module, resource_type, name).

@sreya
Copy link
CollaboratorAuthor

Yeah the problem is the metadata gets assigned to the wrong terraform resource. So on the workspace page, metadata you intend to be displayed alongside the agent is instead hidden on a random resource that you have to open the side bar to see.

This one is working as intended but to give an idea of what i'm describing

image

@github-actionsgithub-actionsbot added the staleThis issue is like stale bread. labelAug 22, 2025
@ThomasK33ThomasK33 deleted the jon/resourcemetadata branchSeptember 15, 2025 07:52
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@johnstcnjohnstcnjohnstcn left review comments

@ethanndicksonethanndicksonethanndickson left review comments

@dannykoppingdannykoppingAwaiting requested review from dannykopping

@spikecurtisspikecurtisAwaiting requested review from spikecurtis

@EmyrkEmyrkAwaiting requested review from Emyrk

Assignees

@ThomasK33ThomasK33

Labels

staleThis issue is like stale bread.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

bug: coder_metadata does not respect resource_idcoder_metadata gets incorrectly assigned to resources

6 participants

@sreya@spikecurtis@johnstcn@ethanndickson@ThomasK33

[8]ページ先頭

©2009-2025 Movatter.jp