Skip to content

Commit dbc530b

Browse files
authored
feat: add session token data source (#120)
1 parent bfa0c5a commit dbc530b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

docs/data-sources/workspace.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ resource "kubernetes_pod" "dev" {
3434
- `owner_email` (String) Email address of the workspace owner.
3535
- `owner_id` (String) UUID of the workspace owner.
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.
37+
- `owner_session_token` (String) Session token for interfacing with a Coder deployment. It is regenerated everytime a workspace is started.
3738
- `start_count` (Number) A computed count based on "transition" state. If "start", count will equal 1.
3839
- `transition` (String) Either "start" or "stop". Use this to start/stop resources with "count".
3940

provider/workspace.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ func workspaceDataSource() *schema.Resource {
5151
}
5252
rd.Set("name", name)
5353

54+
sessionToken := os.Getenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN")
55+
_ = rd.Set("owner_session_token", sessionToken)
56+
5457
id := os.Getenv("CODER_WORKSPACE_ID")
5558
if id == "" {
5659
id = uuid.NewString()
@@ -131,6 +134,11 @@ func workspaceDataSource() *schema.Resource {
131134
Computed: true,
132135
Description: "Name of the workspace.",
133136
},
137+
"owner_session_token": {
138+
Type: schema.TypeString,
139+
Computed: true,
140+
Description: "Session token for interfacing with a Coder deployment. It is regenerated everytime a workspace is started.",
141+
},
134142
},
135143
}
136144
}

provider/workspace_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ package provider_test
33
import (
44
"testing"
55

6-
"github.com/coder/terraform-provider-coder/provider"
76
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
87
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
98
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
109
"github.com/stretchr/testify/require"
10+
11+
"github.com/coder/terraform-provider-coder/provider"
1112
)
1213

1314
func TestWorkspace(t *testing.T) {
1415
t.Setenv("CODER_WORKSPACE_OWNER", "owner123")
1516
t.Setenv("CODER_WORKSPACE_OWNER_EMAIL", "owner123@example.com")
17+
t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN", "abc123")
1618

1719
resource.Test(t, resource.TestCase{
1820
Providers: map[string]*schema.Provider{
@@ -39,6 +41,7 @@ func TestWorkspace(t *testing.T) {
3941
require.Equal(t, "8080", attribs["access_port"])
4042
require.Equal(t, "owner123", attribs["owner"])
4143
require.Equal(t, "owner123@example.com", attribs["owner_email"])
44+
require.Equal(t, "abc123", attribs["owner_session_token"])
4245
return nil
4346
},
4447
}},

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