Skip to content

feat: store coder_workspace_tags in the database #13294

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 27 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
parse
  • Loading branch information
mtojek committed May 17, 2024
commit 0f34937f5cbb1a4e4d7932b47db80b3447baefa0
7 changes: 5 additions & 2 deletions provisioner/terraform/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *server) loadWorkspaceTags(ctx context.Context, module *tfconfig.Module)

for _, dataResource := range module.DataResources {
if dataResource.Type != "coder_workspace_tags" {
s.logger.Debug(ctx, "skip resource as it is not a coder_workspace_tags", "resource_name", dataResource.Name)
s.logger.Debug(ctx, "skip resource as it is not a coder_workspace_tags", "resource_name", dataResource.Name, "resource_type", dataResource.Type)
continue
}

Expand Down Expand Up @@ -114,6 +114,8 @@ func (s *server) loadWorkspaceTags(ctx context.Context, module *tfconfig.Module)
if err != nil {
return nil, xerrors.Errorf("can't preview the resource file: %v", err)
}
key = strings.Trim(key, `"`)

value, err := previewFileContent(tagItem.ValueExpr.Range())
if err != nil {
return nil, xerrors.Errorf("can't preview the resource file: %v", err)
Expand All @@ -124,14 +126,15 @@ func (s *server) loadWorkspaceTags(ctx context.Context, module *tfconfig.Module)
}
}
}
return workspaceTags, nil // TODO
return workspaceTags, nil
}

func previewFileContent(fileRange hcl.Range) (string, error) {
body, err := os.ReadFile(fileRange.Filename)
if err != nil {
return "", err
}
return string(fileRange.SliceBytes(body)), nil

}

Expand Down
12 changes: 10 additions & 2 deletions provisioner/terraform/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestParse(t *testing.T) {
// If ErrorContains is not empty, then the ParseComplete should have an Error containing the given string
ErrorContains string
}{
/*{
{
Name: "single-variable",
Files: map[string]string{
"main.tf": `variable "A" {
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestParse(t *testing.T) {
},
},
},
},*/
},
{
Name: "workspace-tags",
Files: map[string]string{
Expand Down Expand Up @@ -252,6 +252,14 @@ func TestParse(t *testing.T) {
}
}`,
},
Response: &proto.ParseComplete{
WorkspaceTags: map[string]string{
"cluster": `"developers"`,
"os": `data.coder_parameter.os_selector.value`,
"debug": `"${data.coder_parameter.feature_debug_enabled.value}+12345"`,
"cache": `data.coder_parameter.feature_cache_enabled.value == "true" ? "nix-with-cache" : "no-cache"`,
},
},
},
}

Expand Down