Skip to content

Commit b6aa7b5

Browse files
authored
Add data source attribute for owner email address (#31)
* Add data source attributes for owner name and email address * Fix incorrectly commented-out block * Remove "owner_name" field
1 parent 76b9439 commit b6aa7b5

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Diff for: docs/data-sources/workspace.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ resource "kubernetes_pod" "dev" {
3030
- `id` (String) UUID of the workspace.
3131
- `name` (String) Name of the workspace.
3232
- `owner` (String) Username of the workspace owner.
33+
- `owner_email` (String) Email address of the workspace owner.
3334
- `owner_id` (String) UUID of the workspace owner.
3435
- `start_count` (Number) A computed count based on "transition" state. If "start", count will equal 1.
3536
- `transition` (String) Either "start" or "stop". Use this to start/stop resources with "count".

Diff for: internal/provider/provider.go

+14
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,40 @@ func New() *schema.Provider {
6969
count = 1
7070
}
7171
_ = rd.Set("start_count", count)
72+
7273
owner := os.Getenv("CODER_WORKSPACE_OWNER")
7374
if owner == "" {
7475
owner = "default"
7576
}
7677
_ = rd.Set("owner", owner)
78+
79+
ownerEmail := os.Getenv("CODER_WORKSPACE_OWNER_EMAIL")
80+
_ = rd.Set("owner_email", ownerEmail)
81+
7782
ownerID := os.Getenv("CODER_WORKSPACE_OWNER_ID")
7883
if ownerID == "" {
7984
ownerID = uuid.Nil.String()
8085
}
8186
_ = rd.Set("owner_id", ownerID)
87+
8288
name := os.Getenv("CODER_WORKSPACE_NAME")
8389
if name == "" {
8490
name = "default"
8591
}
8692
rd.Set("name", name)
93+
8794
id := os.Getenv("CODER_WORKSPACE_ID")
8895
if id == "" {
8996
id = uuid.NewString()
9097
}
9198
rd.SetId(id)
99+
92100
config, valid := i.(config)
93101
if !valid {
94102
return diag.Errorf("config was unexpected type %q", reflect.TypeOf(i).String())
95103
}
96104
rd.Set("access_url", config.URL.String())
105+
97106
return nil
98107
},
99108
Schema: map[string]*schema.Schema{
@@ -117,6 +126,11 @@ func New() *schema.Provider {
117126
Computed: true,
118127
Description: "Username of the workspace owner.",
119128
},
129+
"owner_email": {
130+
Type: schema.TypeString,
131+
Computed: true,
132+
Description: "Email address of the workspace owner.",
133+
},
120134
"owner_id": {
121135
Type: schema.TypeString,
122136
Computed: true,

Diff for: internal/provider/provider_test.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ func TestProvider(t *testing.T) {
1919
}
2020

2121
func TestWorkspace(t *testing.T) {
22-
t.Parallel()
22+
t.Setenv("CODER_WORKSPACE_OWNER", "owner123")
23+
t.Setenv("CODER_WORKSPACE_OWNER_EMAIL", "[email protected]")
24+
2325
resource.Test(t, resource.TestCase{
2426
Providers: map[string]*schema.Provider{
2527
"coder": provider.New(),
@@ -37,9 +39,13 @@ func TestWorkspace(t *testing.T) {
3739
require.Len(t, state.Modules[0].Resources, 1)
3840
resource := state.Modules[0].Resources["data.coder_workspace.me"]
3941
require.NotNil(t, resource)
40-
value := resource.Primary.Attributes["transition"]
42+
43+
attribs := resource.Primary.Attributes
44+
value := attribs["transition"]
4145
require.NotNil(t, value)
4246
t.Log(value)
47+
require.Equal(t, "owner123", attribs["owner"])
48+
require.Equal(t, "[email protected]", attribs["owner_email"])
4349
return nil
4450
},
4551
}},

0 commit comments

Comments
 (0)