Skip to content

Commit dc475b4

Browse files
committed
feat: add coderd_user data source
1 parent 8c23074 commit dc475b4

File tree

10 files changed

+296
-171
lines changed

10 files changed

+296
-171
lines changed

docs/data-sources/example.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/data-sources/user.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "coderd_user Data Source - coderd"
4+
subcategory: ""
5+
description: |-
6+
An existing user on the coder deployment
7+
---
8+
9+
# coderd_user (Data Source)
10+
11+
An existing user on the coder deployment
12+
13+
14+
15+
<!-- schema generated by tfplugindocs -->
16+
## Schema
17+
18+
### Optional
19+
20+
- `id` (String) The ID of the user to retrieve. This field will be populated if a username is supplied
21+
- `username` (String) The username of the user to retrieve. This field will be populated if an ID is supplied
22+
23+
### Read-Only
24+
25+
- `email` (String) Email of the user.
26+
- `login_type` (String) Type of login for the user. Valid types are 'none', 'password', 'github', and 'oidc'.
27+
- `name` (String) Display name of the user. Defaults to username.
28+
- `roles` (Set of String) Roles assigned to the user. Valid roles are 'owner', 'template-admin', 'user-admin', and 'auditor'.
29+
- `suspended` (Boolean) Whether the user is suspended.

integration/integration_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,23 @@ func TestIntegration(t *testing.T) {
4949

5050
for _, tt := range []struct {
5151
name string
52+
preF func(testing.TB, *codersdk.Client)
5253
assertF func(testing.TB, *codersdk.Client)
5354
}{
5455
{
5556
name: "user-test",
57+
preF: func(t testing.TB, c *codersdk.Client) {
58+
me, err := c.User(ctx, codersdk.Me)
59+
require.NoError(t, err)
60+
c.CreateUser(ctx, codersdk.CreateUserRequest{
61+
62+
Username: "ethan",
63+
Password: "SomeSecurePassword!",
64+
UserLoginType: "password",
65+
DisableLogin: false,
66+
OrganizationID: me.OrganizationIDs[0],
67+
})
68+
},
5669
assertF: func(t testing.TB, c *codersdk.Client) {
5770
// Check user fields.
5871
user, err := c.User(ctx, "dean")
@@ -102,6 +115,7 @@ func TestIntegration(t *testing.T) {
102115
var buf bytes.Buffer
103116
tfCmd.Stdout = &buf
104117
tfCmd.Stderr = &buf
118+
tt.preF(t, client)
105119
if err := tfCmd.Run(); !assert.NoError(t, err) {
106120
t.Logf(buf.String())
107121
}

integration/user-test/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ resource "coderd_user" "dean" {
1616
password = "SomeSecurePassword!"
1717
suspended = false
1818
}
19+
20+
data "coderd_user" "ethan" {
21+
username = "ethan"
22+
}

internal/provider/example_data_source.go

Lines changed: 0 additions & 105 deletions
This file was deleted.

internal/provider/example_data_source_test.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

internal/provider/provider.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (p *CoderdProvider) Resources(ctx context.Context) []func() resource.Resour
112112

113113
func (p *CoderdProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
114114
return []func() datasource.DataSource{
115-
NewExampleDataSource,
115+
NewUserDataSource,
116116
}
117117
}
118118

0 commit comments

Comments
 (0)