Skip to content

feat: add coderd_user data source #19

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

Merged
merged 10 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
30 changes: 0 additions & 30 deletions docs/data-sources/example.md

This file was deleted.

29 changes: 29 additions & 0 deletions docs/data-sources/user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "coderd_user Data Source - coderd"
subcategory: ""
description: |-
An existing user on the coder deployment
---

# coderd_user (Data Source)

An existing user on the coder deployment



<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `id` (String) The ID of the user to retrieve. This field will be populated if a username is supplied
- `username` (String) The username of the user to retrieve. This field will be populated if an ID is supplied

### Read-Only

- `email` (String) Email of the user.
- `login_type` (String) Type of login for the user. Valid types are 'none', 'password', 'github', and 'oidc'.
- `name` (String) Display name of the user. Defaults to username.
- `roles` (Set of String) Roles assigned to the user. Valid roles are 'owner', 'template-admin', 'user-admin', and 'auditor'.
- `suspended` (Boolean) Whether the user is suspended.
15 changes: 15 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,24 @@ func TestIntegration(t *testing.T) {

for _, tt := range []struct {
name string
preF func(testing.TB, *codersdk.Client)
assertF func(testing.TB, *codersdk.Client)
}{
{
name: "user-test",
preF: func(t testing.TB, c *codersdk.Client) {
me, err := c.User(ctx, codersdk.Me)
assert.NoError(t, err)
_, err = c.CreateUser(ctx, codersdk.CreateUserRequest{
Email: "[email protected]",
Username: "ethan",
Password: "SomeSecurePassword!",
UserLoginType: "password",
DisableLogin: false,
OrganizationID: me.OrganizationIDs[0],
})
assert.NoError(t, err)
},
assertF: func(t testing.TB, c *codersdk.Client) {
// Check user fields.
user, err := c.User(ctx, "dean")
Expand Down Expand Up @@ -102,6 +116,7 @@ func TestIntegration(t *testing.T) {
var buf bytes.Buffer
tfCmd.Stdout = &buf
tfCmd.Stderr = &buf
tt.preF(t, client)
if err := tfCmd.Run(); !assert.NoError(t, err) {
t.Logf(buf.String())
}
Expand Down
4 changes: 4 additions & 0 deletions integration/user-test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ resource "coderd_user" "dean" {
password = "SomeSecurePassword!"
suspended = false
}

data "coderd_user" "ethan" {
username = "ethan"
}
105 changes: 0 additions & 105 deletions internal/provider/example_data_source.go

This file was deleted.

32 changes: 0 additions & 32 deletions internal/provider/example_data_source_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (p *CoderdProvider) Resources(ctx context.Context) []func() resource.Resour

func (p *CoderdProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
NewExampleDataSource,
NewUserDataSource,
}
}

Expand Down
Loading
Loading