Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9bae197

Browse files
committed
feat: Add rbac_roles to coder_workspace_owner data source
1 parent054e9bc commit9bae197

File tree

6 files changed

+26
-0
lines changed

6 files changed

+26
-0
lines changed

‎docs/data-sources/workspace_owner.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ resource "coder_env" "git_author_email" {
5353
-`login_type` (String) The type of login the user has.
5454
-`name` (String) The username of the user.
5555
-`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.
56+
-`rbac_roles` (List of String) The RBAC roles of which the user is assigned.
5657
-`session_token` (String) Session token for authenticating with a Coder deployment. It is regenerated every time a workspace is started.
5758
-`ssh_private_key` (String, Sensitive) The user's generated SSH private key.
5859
-`ssh_public_key` (String) The user's generated SSH public key.

‎integration/integration_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ func TestIntegration(t *testing.T) {
113113
"workspace_owner.ssh_private_key":`(?s)^.+?BEGIN OPENSSH PRIVATE KEY.+?END OPENSSH PRIVATE KEY.+?$`,
114114
"workspace_owner.ssh_public_key":`(?s)^ssh-ed25519.+$`,
115115
"workspace_owner.login_type":``,
116+
"workspace_owner.rbac_roles":`\[\]`,
116117
},
117118
},
118119
{
@@ -141,6 +142,7 @@ func TestIntegration(t *testing.T) {
141142
"workspace_owner.ssh_private_key":`(?s)^.+?BEGIN OPENSSH PRIVATE KEY.+?END OPENSSH PRIVATE KEY.+?$`,
142143
"workspace_owner.ssh_public_key":`(?s)^ssh-ed25519.+$`,
143144
"workspace_owner.login_type":`password`,
145+
"workspace_owner.rbac_roles":`\[\]`,
144146
},
145147
},
146148
{

‎integration/workspace-owner-filled/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ locals {
4040
"workspace_owner.ssh_private_key": data.coder_workspace_owner.me.ssh_private_key,
4141
"workspace_owner.ssh_public_key": data.coder_workspace_owner.me.ssh_public_key,
4242
"workspace_owner.login_type": data.coder_workspace_owner.me.login_type,
43+
"workspace_owner.rbac_roles":jsonencode(data.coder_workspace_owner.me.rbac_roles),
4344
}
4445
}
4546

‎integration/workspace-owner/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ locals {
4040
"workspace_owner.ssh_private_key": data.coder_workspace_owner.me.ssh_private_key,
4141
"workspace_owner.ssh_public_key": data.coder_workspace_owner.me.ssh_public_key,
4242
"workspace_owner.login_type": data.coder_workspace_owner.me.login_type,
43+
"workspace_owner.rbac_roles":jsonencode(data.coder_workspace_owner.me.rbac_roles),
4344
}
4445
}
4546

‎provider/workspace_owner.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ func workspaceOwnerDataSource() *schema.Resource {
5959
_=rd.Set("login_type",loginType)
6060
}
6161

62+
varrbacRoles []string
63+
ifrolesRaw,ok:=os.LookupEnv("CODER_WORKSPACE_OWNER_RBAC_ROLES");ok {
64+
iferr:=json.NewDecoder(strings.NewReader(rolesRaw)).Decode(&rbacRoles);err!=nil {
65+
returndiag.Errorf("invalid user rbac roles: %s",err.Error())
66+
}
67+
}
68+
_=rd.Set("rbac_roles",rbacRoles)
69+
6270
returndiags
6371
},
6472
Schema:map[string]*schema.Schema{
@@ -118,6 +126,14 @@ func workspaceOwnerDataSource() *schema.Resource {
118126
Computed:true,
119127
Description:"The type of login the user has.",
120128
},
129+
"rbac_roles": {
130+
Type:schema.TypeList,
131+
Elem:&schema.Schema{
132+
Type:schema.TypeString,
133+
},
134+
Computed:true,
135+
Description:"The RBAC roles of which the user is assigned.",
136+
},
121137
},
122138
}
123139
}

‎provider/workspace_owner_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
3434
t.Setenv("CODER_WORKSPACE_OWNER_SESSION_TOKEN",`supersecret`)
3535
t.Setenv("CODER_WORKSPACE_OWNER_OIDC_ACCESS_TOKEN",`alsosupersecret`)
3636
t.Setenv("CODER_WORKSPACE_OWNER_LOGIN_TYPE",`github`)
37+
t.Setenv("CODER_WORKSPACE_OWNER_RBAC_ROLES",`["member", "auditor"]`)
3738

3839
resource.Test(t, resource.TestCase{
3940
ProviderFactories:coderFactory(),
@@ -61,6 +62,8 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
6162
assert.Equal(t,`supersecret`,attrs["session_token"])
6263
assert.Equal(t,`alsosupersecret`,attrs["oidc_access_token"])
6364
assert.Equal(t,`github`,attrs["login_type"])
65+
assert.Equal(t,`member`,attrs["rbac_roles.0"])
66+
assert.Equal(t,`auditor`,attrs["rbac_roles.1"])
6467

6568
returnnil
6669
},
@@ -80,6 +83,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
8083
"CODER_WORKSPACE_OWNER_SSH_PUBLIC_KEY",
8184
"CODER_WORKSPACE_OWNER_SSH_PRIVATE_KEY",
8285
"CODER_WORKSPACE_OWNER_LOGIN_TYPE",
86+
"CODER_WORKSPACE_OWNER_RBAC_ROLES",
8387
} {// https://github.com/golang/go/issues/52817
8488
t.Setenv(v,"")
8589
os.Unsetenv(v)
@@ -110,6 +114,7 @@ func TestWorkspaceOwnerDatasource(t *testing.T) {
110114
assert.Empty(t,attrs["session_token"])
111115
assert.Empty(t,attrs["oidc_access_token"])
112116
assert.Empty(t,attrs["login_type"])
117+
assert.Empty(t,attrs["rbac_roles.0"])
113118
returnnil
114119
},
115120
}},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp