Skip to content

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

Merged
merged 10 commits into from
May 16, 2024
Merged

feat: support workspace tags #223

merged 10 commits into from
May 16, 2024

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented May 10, 2024

Related: coder/coder#13218

This PR adds Terraform definition for coder_workspace_tags with resource reference tests.

@mtojek mtojek self-assigned this May 10, 2024
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())
Copy link
Member Author

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:

  1. Pass CODER_TF_WORK_DIR from provisioner with disk path to the template.
  2. Use terraform-config-inspect to load module and get references (filename + pos) to data resources.
  3. 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.

Copy link
Contributor

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

Copy link
Member Author

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.

@mtojek mtojek marked this pull request as ready for review May 15, 2024 10:50
}

data "coder_workspace_tags" "custom_workspace_tags" {
tag {
Copy link
Contributor

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.

Copy link
Member Author

@mtojek mtojek May 15, 2024

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())
Copy link
Contributor

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

@mtojek mtojek requested a review from spikecurtis May 15, 2024 15:30
@mtojek mtojek merged commit 041e000 into main May 16, 2024
11 checks passed
@mtojek mtojek deleted the 13218-workspace-tags branch May 16, 2024 15:29
@github-actions github-actions bot locked and limited conversation to collaborators May 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants