coder / coder/terraform-provider-coder

`coder_metadata` gets incorrectly assigned to resources

Open
#306 9 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
60
Forks
27
Avg merge
1d 21h
Merged PRs (30d)
2

Description

Currently, the Terraform provisioner relies on the output of `terraform graph` to determine what resource `coder_metadata` instances should be applied to when building the template or workspace.

Unfortunately, it's very reasonable for a user to write a template where the output of `terraform graph` does not meet what's required to correctly map the metadata to the resource, such as when using the contents of another resource to populate a field. This results in the UI showing metadata intended for one resource on another.

Here's a minimal example of this using `null_resource`s:

```tf
resource "coder_agent" "main" {
os = "linux"
arch = "amd64"
}

// Agent resource
resource "null_resource" "about" {
depends_on = [
coder_agent.main,
]
triggers = {
name = "Null About"
}
}

// Some secondary resource, such as a volume, pointing to the agent resource
resource "null_resource" "other" {
triggers = {
about_name = null_resource.about.triggers.name
}
}

// Metadata pointing to the agent resource and the volume
resource "coder_metadata" "about_info" {
resource_id = null_resource.about.id
item {
key = "other-reference"
value = null_resource.other.triggers.about_name
}
}
```

The graph output of this template is then:
![image](https://github.com/user-attachments/assets/7d640ab4-b5f1-4430-9098-4ab3fb84b086)

Since `null_resource.other` is the closest resource to `coder_metadata.about_info`, the metadata gets assigned to it, instead of `null_resource.about`, as was indicated in the template.

The same graph and graph traversal algorithm is used to determine which resource the agent exists within, so it's possible (but not proven) that this same issue effects assigning the agent to a resource.

Regardless, this should be a purely cosmetic bug, and shouldn't have any bearing on anything outside of how workspace metadata is shown in the UI.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.