-
Notifications
You must be signed in to change notification settings - Fork 22
feat: support workspace tags #223
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
return &schema.Resource{ | ||
Description: "Use this data source to configure workspace tags to select provisioners.", | ||
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
rd.SetId(uuid.NewString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reviewers:
Originally I wanted to place here the logic to load HCL files and read raw content of value
properties. Unfortunately, I hit an interface blocker. Here is the story:
- Pass
CODER_TF_WORK_DIR
from provisioner with disk path to the template. - Use terraform-config-inspect to load module and get references (filename + pos) to data resources.
- Read raw attributes of the relevant data resource.
BUT...
schema.ResourceData
is not aware of its own identity. It knows only its child properties, raw config and state diff. I'm afraid this is a blocker we can't find a workaround for, and we have to implement this logic in coderd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we want or need to do this here. This gets called at build time to allow other terraform resources to read data. I think we can just return the actual tag values and call it a day.
The loading of the files and parsing HCL should happen during the template version import, where we already have access to the raw files: https://github.com/coder/coder/blob/f14927955d7361d9a50c633e69fbebca2d9946cb/provisioner/terraform/parse.go#L26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we want or need to do this here.
I didn't want to leak HCL parsing from the provider, but as long as we're doing it in template version import, I will extend that part.
} | ||
|
||
data "coder_workspace_tags" "custom_workspace_tags" { | ||
tag { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tags are a map string -> string
, so why is the syntax a list of tuples? This allows you to specify the same name more than once which is an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I can switch this to map, but keep in mind that it won't prevent the issue you mentioned (the same name more than once), as multiple coder_workspace_tags
can exist, right?
EDIT:
switched to map
return &schema.Resource{ | ||
Description: "Use this data source to configure workspace tags to select provisioners.", | ||
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics { | ||
rd.SetId(uuid.NewString()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why we want or need to do this here. This gets called at build time to allow other terraform resources to read data. I think we can just return the actual tag values and call it a day.
The loading of the files and parsing HCL should happen during the template version import, where we already have access to the raw files: https://github.com/coder/coder/blob/f14927955d7361d9a50c633e69fbebca2d9946cb/provisioner/terraform/parse.go#L26
Related: coder/coder#13218
This PR adds Terraform definition for
coder_workspace_tags
with resource reference tests.