diff --git a/docs/data-sources/workspace.md b/docs/data-sources/workspace.md index c736f78a..4733edd4 100644 --- a/docs/data-sources/workspace.md +++ b/docs/data-sources/workspace.md @@ -36,4 +36,6 @@ resource "kubernetes_pod" "dev" { - `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. - `owner_session_token` (String) Session token for authenticating with a Coder deployment. It is regenerated everytime a workspace is started. - `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. - `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 995cb6e4..a6ea64f6 100644 --- a/provider/workspace.go +++ b/provider/workspace.go @@ -60,6 +60,12 @@ func workspaceDataSource() *schema.Resource { } rd.SetId(id) + templateID := os.Getenv("CODER_WORKSPACE_TEMPLATE_ID") + _ = rd.Set("template_id", templateID) + + templateName := os.Getenv("CODER_WORKSPACE_TEMPLATE_NAME") + _ = rd.Set("template_name", templateName) + config, valid := i.(config) if !valid { return diag.Errorf("config was unexpected type %q", reflect.TypeOf(i).String()) @@ -139,6 +145,16 @@ func workspaceDataSource() *schema.Resource { Computed: true, Description: "Session token for authenticating with a Coder deployment. It is regenerated everytime a workspace is started.", }, + "template_id": { + Type: schema.TypeString, + Computed: true, + Description: "ID of the workspace's template.", + }, + "template_name": { + Type: schema.TypeString, + Computed: true, + Description: "Name of the workspace's template.", + }, }, } } diff --git a/provider/workspace_test.go b/provider/workspace_test.go index 7662f4bc..69c64992 100644 --- a/provider/workspace_test.go +++ b/provider/workspace_test.go @@ -15,6 +15,8 @@ func TestWorkspace(t *testing.T) { t.Setenv("CODER_WORKSPACE_OWNER", "owner123") t.Setenv("CODER_WORKSPACE_OWNER_EMAIL", "owner123@example.com") t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN", "abc123") + t.Setenv("CODER_WORKSPACE_TEMPLATE_ID", "templateID") + t.Setenv("CODER_WORKSPACE_TEMPLATE_NAME", "template123") resource.Test(t, resource.TestCase{ Providers: map[string]*schema.Provider{ @@ -42,6 +44,8 @@ func TestWorkspace(t *testing.T) { require.Equal(t, "owner123", attribs["owner"]) require.Equal(t, "owner123@example.com", attribs["owner_email"]) require.Equal(t, "abc123", attribs["owner_session_token"]) + require.Equal(t, "templateID", attribs["template_id"]) + require.Equal(t, "template123", attribs["template_name"]) return nil }, }}, @@ -71,6 +75,8 @@ func TestWorkspace(t *testing.T) { require.Equal(t, "https://example.com:8080", attribs["access_url"]) require.Equal(t, "owner123", attribs["owner"]) require.Equal(t, "owner123@example.com", attribs["owner_email"]) + require.Equal(t, "templateID", attribs["template_id"]) + require.Equal(t, "template123", attribs["template_name"]) return nil }, }},