Skip to content

feat: add owner_oidc_refresh_token to coder_workspace_owner data source #264

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

Closed
wants to merge 2 commits into from
Closed
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_owner.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ resource "coder_env" "git_author_email" {
- `id` (String) The UUID of the workspace owner.
- `name` (String) The username of the user.
- `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.
- `oidc_refresh_token` (String) A valid OpenID Connect refresh token of the workspace owner. Can be used to refresh access token if expired This is only available if the workspace owner authenticated with OpenID Connect. If a valid refresh token cannot be obtained, this value will be an empty string.
- `session_token` (String) Session token for authenticating with a Coder deployment. It is regenerated every time a workspace is started.
- `ssh_private_key` (String, Sensitive) The user's generated SSH private key.
- `ssh_public_key` (String) The user's generated SSH public key.
8 changes: 8 additions & 0 deletions provider/workspace_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func workspaceOwnerDataSource() *schema.Resource {

_ = rd.Set("session_token", os.Getenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN"))
_ = rd.Set("oidc_access_token", os.Getenv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN"))
_ = rd.Set("oidc_refresh_token", os.Getenv("CODER_WORKSPACE_OWNER_OIDC_REFRESH_TOKEN"))

return nil
},
Expand Down Expand Up @@ -107,6 +108,13 @@ func workspaceOwnerDataSource() *schema.Resource {
"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.",
},
"oidc_refresh_token": {
Type: schema.TypeString,
Computed: true,
Description: "A valid OpenID Connect refresh token of the workspace owner. Can be used to refresh access token if expired " +
"This is only available if the workspace owner authenticated with OpenID Connect. " +
"If a valid refresh token cannot be obtained, this value will be an empty string.",
},
},
}
}
4 changes: 4 additions & 0 deletions provider/workspace_owner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
t.Setenv("CODER_WORKSPACE_OWNER_GROUPS", `["group1", "group2"]`)
t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN", `supersecret`)
t.Setenv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN", `alsosupersecret`)
t.Setenv("CODER_WORKSPACE_OWNER_OIDC_REFRESH_TOKEN", `alsosupersecretrefresh`)

resource.Test(t, resource.TestCase{
Providers: map[string]*schema.Provider{
Expand Down Expand Up @@ -63,6 +64,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
assert.Equal(t, `group2`, attrs["groups.1"])
assert.Equal(t, `supersecret`, attrs["session_token"])
assert.Equal(t, `alsosupersecret`, attrs["oidc_access_token"])
assert.Equal(t, `alsosupersecretrefresh`, attrs["oidc_refresh_token"])
return nil
},
}},
Expand All @@ -80,6 +82,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
"CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN",
"CODER_WORKSPACE_OWNER_SSH_PUBLIC_KEY",
"CODER_WORKSPACE_OWNER_SSH_PRIVATE_KEY",
"CODER_WORKSPACE_OWNER_OIDC_REFRESH_TOKEN",
} { // https://github.com/golang/go/issues/52817
t.Setenv(v, "")
os.Unsetenv(v)
Expand Down Expand Up @@ -111,6 +114,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
assert.Empty(t, attrs["groups.0"])
assert.Empty(t, attrs["session_token"])
assert.Empty(t, attrs["oidc_access_token"])
assert.Empty(t, attrs["oidc_refresh_token"])
return nil
},
}},
Expand Down
Loading