Skip to content

feat(workspace): add the template version also #166

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 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions docs/data-sources/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ resource "kubernetes_pod" "dev" {
- `start_count` (Number) A computed count based on "transition" state. If "start", count will equal 1.
- `template_id` (String) ID of the workspace's template.
- `template_name` (String) Name of the workspace's template.
- `template_version` (String) Version of the workspace's template.
- `transition` (String) Either "start" or "stop". Use this to start/stop resources with "count".
8 changes: 8 additions & 0 deletions provider/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func workspaceDataSource() *schema.Resource {
templateName := os.Getenv("CODER_WORKSPACE_TEMPLATE_NAME")
_ = rd.Set("template_name", templateName)

templateVersion := os.Getenv("CODER_WORKSPACE_TEMPLATE_VERSION")
_ = rd.Set("template_version", templateVersion)

config, valid := i.(config)
if !valid {
return diag.Errorf("config was unexpected type %q", reflect.TypeOf(i).String())
Expand Down Expand Up @@ -155,6 +158,11 @@ func workspaceDataSource() *schema.Resource {
Computed: true,
Description: "Name of the workspace's template.",
},
"template_version": {
Type: schema.TypeString,
Computed: true,
Description: "Version of the workspace's template.",
},
},
}
}
3 changes: 3 additions & 0 deletions provider/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestWorkspace(t *testing.T) {
t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN", "abc123")
t.Setenv("CODER_WORKSPACE_TEMPLATE_ID", "templateID")
t.Setenv("CODER_WORKSPACE_TEMPLATE_NAME", "template123")
t.Setenv("CODER_WORKSPACE_TEMPLATE_VERSION", "v1.2.3")

resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
Expand Down Expand Up @@ -46,6 +47,7 @@ func TestWorkspace(t *testing.T) {
require.Equal(t, "abc123", attribs["owner_session_token"])
require.Equal(t, "templateID", attribs["template_id"])
require.Equal(t, "template123", attribs["template_name"])
require.Equal(t, "v1.2.3", attribs["template_version"])
return nil
},
}},
Expand Down Expand Up @@ -77,6 +79,7 @@ func TestWorkspace(t *testing.T) {
require.Equal(t, "[email protected]", attribs["owner_email"])
require.Equal(t, "templateID", attribs["template_id"])
require.Equal(t, "template123", attribs["template_name"])
require.Equal(t, "v1.2.3", attribs["template_version"])
return nil
},
}},
Expand Down