diff --git a/docs/data-sources/workspace.md b/docs/data-sources/workspace.md index 4733edd4..5193dbe1 100644 --- a/docs/data-sources/workspace.md +++ b/docs/data-sources/workspace.md @@ -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". diff --git a/provider/workspace.go b/provider/workspace.go index a6ea64f6..4b1aa526 100644 --- a/provider/workspace.go +++ b/provider/workspace.go @@ -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()) @@ -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.", + }, }, } } diff --git a/provider/workspace_test.go b/provider/workspace_test.go index 69c64992..b40d86fe 100644 --- a/provider/workspace_test.go +++ b/provider/workspace_test.go @@ -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{ @@ -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 }, }}, @@ -77,6 +79,7 @@ func TestWorkspace(t *testing.T) { require.Equal(t, "owner123@example.com", 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 }, }},