Skip to content

Commit 73943b2

Browse files
authored
feat: add template_id and template_name to workspace data source (#158)
1 parent ac4d723 commit 73943b2

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

docs/data-sources/workspace.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,6 @@ resource "kubernetes_pod" "dev" {
3636
- `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.
3737
- `owner_session_token` (String) Session token for authenticating with a Coder deployment. It is regenerated everytime a workspace is started.
3838
- `start_count` (Number) A computed count based on "transition" state. If "start", count will equal 1.
39+
- `template_id` (String) ID of the workspace's template.
40+
- `template_name` (String) Name of the workspace's template.
3941
- `transition` (String) Either "start" or "stop". Use this to start/stop resources with "count".

provider/workspace.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ func workspaceDataSource() *schema.Resource {
6060
}
6161
rd.SetId(id)
6262

63+
templateID := os.Getenv("CODER_WORKSPACE_TEMPLATE_ID")
64+
_ = rd.Set("template_id", templateID)
65+
66+
templateName := os.Getenv("CODER_WORKSPACE_TEMPLATE_NAME")
67+
_ = rd.Set("template_name", templateName)
68+
6369
config, valid := i.(config)
6470
if !valid {
6571
return diag.Errorf("config was unexpected type %q", reflect.TypeOf(i).String())
@@ -139,6 +145,16 @@ func workspaceDataSource() *schema.Resource {
139145
Computed: true,
140146
Description: "Session token for authenticating with a Coder deployment. It is regenerated everytime a workspace is started.",
141147
},
148+
"template_id": {
149+
Type: schema.TypeString,
150+
Computed: true,
151+
Description: "ID of the workspace's template.",
152+
},
153+
"template_name": {
154+
Type: schema.TypeString,
155+
Computed: true,
156+
Description: "Name of the workspace's template.",
157+
},
142158
},
143159
}
144160
}

provider/workspace_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ func TestWorkspace(t *testing.T) {
1515
t.Setenv("CODER_WORKSPACE_OWNER", "owner123")
1616
t.Setenv("CODER_WORKSPACE_OWNER_EMAIL", "owner123@example.com")
1717
t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN", "abc123")
18+
t.Setenv("CODER_WORKSPACE_TEMPLATE_ID", "templateID")
19+
t.Setenv("CODER_WORKSPACE_TEMPLATE_NAME", "template123")
1820

1921
resource.Test(t, resource.TestCase{
2022
Providers: map[string]*schema.Provider{
@@ -42,6 +44,8 @@ func TestWorkspace(t *testing.T) {
4244
require.Equal(t, "owner123", attribs["owner"])
4345
require.Equal(t, "owner123@example.com", attribs["owner_email"])
4446
require.Equal(t, "abc123", attribs["owner_session_token"])
47+
require.Equal(t, "templateID", attribs["template_id"])
48+
require.Equal(t, "template123", attribs["template_name"])
4549
return nil
4650
},
4751
}},
@@ -71,6 +75,8 @@ func TestWorkspace(t *testing.T) {
7175
require.Equal(t, "https://example.com:8080", attribs["access_url"])
7276
require.Equal(t, "owner123", attribs["owner"])
7377
require.Equal(t, "owner123@example.com", attribs["owner_email"])
78+
require.Equal(t, "templateID", attribs["template_id"])
79+
require.Equal(t, "template123", attribs["template_name"])
7480
return nil
7581
},
7682
}},

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy