Skip to content

Commit a5bd88b

Browse files
committed
switch back to list
1 parent d96eefd commit a5bd88b

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

docs/data-sources/workspace.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ resource "kubernetes_pod" "dev" {
3232
- `name` (String) Name of the workspace.
3333
- `owner` (String) Username of the workspace owner.
3434
- `owner_email` (String) Email address of the workspace owner.
35-
- `owner_groups` (String) Comma separated list of groups the workspace owner belongs to.
35+
- `owner_groups` (List of String) List of groups the workspace owner belongs to.
3636
- `owner_id` (String) UUID of the workspace owner.
3737
- `owner_name` (String) Name of the workspace owner.
3838
- `owner_oidc_access_token` (String) A valid OpenID Connect access token of the workspace owner. This is only available if the workspace owner authenticated with OpenID Connect. If a valid token cannot be obtained, this value will be an empty string.

provider/workspace.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package provider
22

33
import (
44
"context"
5+
"encoding/json"
56
"os"
67
"reflect"
78
"strconv"
@@ -36,7 +37,12 @@ func workspaceDataSource() *schema.Resource {
3637
ownerEmail := os.Getenv("CODER_WORKSPACE_OWNER_EMAIL")
3738
_ = rd.Set("owner_email", ownerEmail)
3839

39-
ownerGroups := os.Getenv("CODER_WORKSPACE_OWNER_GROUPS")
40+
ownerGroupsText := os.Getenv("CODER_WORKSPACE_OWNER_GROUPS")
41+
var ownerGroups []string
42+
err := json.Unmarshal([]byte(ownerGroupsText), &ownerGroups)
43+
if err != nil {
44+
return diag.Errorf("couldn't parse owner groups %q", ownerGroupsText)
45+
}
4046
_ = rd.Set("owner_groups", ownerGroups)
4147

4248
ownerName := os.Getenv("CODER_WORKSPACE_OWNER_NAME")
@@ -145,9 +151,10 @@ func workspaceDataSource() *schema.Resource {
145151
"If a valid token cannot be obtained, this value will be an empty string.",
146152
},
147153
"owner_groups": {
148-
Type: schema.TypeString,
154+
Type: schema.TypeList,
155+
Elem: &schema.Schema{Type: schema.TypeString},
149156
Computed: true,
150-
Description: "Comma separated list of groups the workspace owner belongs to.",
157+
Description: "List of groups the workspace owner belongs to.",
151158
},
152159
"id": {
153160
Type: schema.TypeString,

provider/workspace_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestWorkspace(t *testing.T) {
1616
t.Setenv("CODER_WORKSPACE_OWNER_NAME", "Mr Owner")
1717
t.Setenv("CODER_WORKSPACE_OWNER_EMAIL", "[email protected]")
1818
t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN", "abc123")
19-
t.Setenv("CODER_WORKSPACE_OWNER_GROUPS", "group1,group2")
19+
t.Setenv("CODER_WORKSPACE_OWNER_GROUPS", "[\"group1\",\"group2\"]")
2020
t.Setenv("CODER_WORKSPACE_TEMPLATE_ID", "templateID")
2121
t.Setenv("CODER_WORKSPACE_TEMPLATE_NAME", "template123")
2222
t.Setenv("CODER_WORKSPACE_TEMPLATE_VERSION", "v1.2.3")
@@ -48,7 +48,8 @@ func TestWorkspace(t *testing.T) {
4848
require.Equal(t, "Mr Owner", attribs["owner_name"])
4949
require.Equal(t, "[email protected]", attribs["owner_email"])
5050
require.Equal(t, "abc123", attribs["owner_session_token"])
51-
require.Equal(t, "group1,group2", attribs["owner_groups"])
51+
require.Equal(t, "group1", attribs["owner_groups.0"])
52+
require.Equal(t, "group2", attribs["owner_groups.1"])
5253
require.Equal(t, "templateID", attribs["template_id"])
5354
require.Equal(t, "template123", attribs["template_name"])
5455
require.Equal(t, "v1.2.3", attribs["template_version"])
@@ -82,7 +83,8 @@ func TestWorkspace(t *testing.T) {
8283
require.Equal(t, "owner123", attribs["owner"])
8384
require.Equal(t, "Mr Owner", attribs["owner_name"])
8485
require.Equal(t, "[email protected]", attribs["owner_email"])
85-
require.Equal(t, "group1,group2", attribs["owner_groups"])
86+
require.Equal(t, "group1", attribs["owner_groups.0"])
87+
require.Equal(t, "group2", attribs["owner_groups.1"])
8688
require.Equal(t, "templateID", attribs["template_id"])
8789
require.Equal(t, "template123", attribs["template_name"])
8890
require.Equal(t, "v1.2.3", attribs["template_version"])

0 commit comments

Comments
 (0)