Skip to content
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

feat: add coderd_user data source #19

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

This file was deleted.

33 changes: 33 additions & 0 deletions docs/data-sources/user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
# 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

- `created_at` (Number) Unix timestamp of when the user was created.
- `email` (String) Email of the user.
- `last_seen_at` (Number) Unix timestamp of when the user was last seen.
- `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.
- `organization_ids` (Set of String) IDs of organizations the user is associated with.
- `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.
- `theme_preference` (String) The user's preferred theme.
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
14 changes: 14 additions & 0 deletions integration/user-test/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ resource "coderd_user" "dean" {
password = "SomeSecurePassword!"
suspended = false
}

data "coderd_user" "ethan" {
username = "ethan"
}
ethanndickson marked this conversation as resolved.
Show resolved Hide resolved

resource "coderd_user" "ethan2" {
username = "${data.coderd_user.ethan.username}2"
name = "${data.coderd_user.ethan.name}2"
email = "${data.coderd_user.ethan.email}.au"
login_type = "${data.coderd_user.ethan.login_type}"
roles = data.coderd_user.ethan.roles
suspended = data.coderd_user.ethan.suspended
}

104 changes: 0 additions & 104 deletions internal/provider/example_data_source.go

This file was deleted.

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

This file was deleted.

5 changes: 1 addition & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package provider

import (
Expand Down Expand Up @@ -112,7 +109,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