Skip to content

Commit 0f34937

Browse files
committed
parse
1 parent 8507793 commit 0f34937

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

provisioner/terraform/parse.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (s *server) loadWorkspaceTags(ctx context.Context, module *tfconfig.Module)
7171

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

@@ -114,6 +114,8 @@ func (s *server) loadWorkspaceTags(ctx context.Context, module *tfconfig.Module)
114114
if err != nil {
115115
return nil, xerrors.Errorf("can't preview the resource file: %v", err)
116116
}
117+
key = strings.Trim(key, `"`)
118+
117119
value, err := previewFileContent(tagItem.ValueExpr.Range())
118120
if err != nil {
119121
return nil, xerrors.Errorf("can't preview the resource file: %v", err)
@@ -124,14 +126,15 @@ func (s *server) loadWorkspaceTags(ctx context.Context, module *tfconfig.Module)
124126
}
125127
}
126128
}
127-
return workspaceTags, nil // TODO
129+
return workspaceTags, nil
128130
}
129131

130132
func previewFileContent(fileRange hcl.Range) (string, error) {
131133
body, err := os.ReadFile(fileRange.Filename)
132134
if err != nil {
133135
return "", err
134136
}
137+
return string(fileRange.SliceBytes(body)), nil
135138

136139
}
137140

provisioner/terraform/parse_test.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestParse(t *testing.T) {
2323
// If ErrorContains is not empty, then the ParseComplete should have an Error containing the given string
2424
ErrorContains string
2525
}{
26-
/*{
26+
{
2727
Name: "single-variable",
2828
Files: map[string]string{
2929
"main.tf": `variable "A" {
@@ -200,7 +200,7 @@ func TestParse(t *testing.T) {
200200
},
201201
},
202202
},
203-
},*/
203+
},
204204
{
205205
Name: "workspace-tags",
206206
Files: map[string]string{
@@ -252,6 +252,14 @@ func TestParse(t *testing.T) {
252252
}
253253
}`,
254254
},
255+
Response: &proto.ParseComplete{
256+
WorkspaceTags: map[string]string{
257+
"cluster": `"developers"`,
258+
"os": `data.coder_parameter.os_selector.value`,
259+
"debug": `"${data.coder_parameter.feature_debug_enabled.value}+12345"`,
260+
"cache": `data.coder_parameter.feature_cache_enabled.value == "true" ? "nix-with-cache" : "no-cache"`,
261+
},
262+
},
255263
},
256264
}
257265

0 commit comments

Comments
 (0)