Skip to content

Commit 8416e35

Browse files
feat: add coderd_user data source (#19)
1 parent 144ff73 commit 8416e35

File tree

11 files changed

+351
-183
lines changed

11 files changed

+351
-183
lines changed

docs/data-sources/example.md

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

docs/data-sources/user.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
- `created_at` (Number) Unix timestamp of when the user was created.
26+
- `email` (String) Email of the user.
27+
- `last_seen_at` (Number) Unix timestamp of when the user was last seen.
28+
- `login_type` (String) Type of login for the user. Valid types are 'none', 'password', 'github', and 'oidc'.
29+
- `name` (String) Display name of the user. Defaults to username.
30+
- `organization_ids` (Set of String) IDs of organizations the user is associated with.
31+
- `roles` (Set of String) Roles assigned to the user. Valid roles are 'owner', 'template-admin', 'user-admin', and 'auditor'.
32+
- `suspended` (Boolean) Whether the user is suspended.
33+
- `theme_preference` (String) The user's preferred theme.

integration/integration_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,24 @@ func TestIntegration(t *testing.T) {
4242

4343
for _, tt := range []struct {
4444
name string
45+
preF func(testing.TB, *codersdk.Client)
4546
assertF func(testing.TB, *codersdk.Client)
4647
}{
4748
{
4849
name: "user-test",
50+
preF: func(t testing.TB, c *codersdk.Client) {
51+
me, err := c.User(ctx, codersdk.Me)
52+
assert.NoError(t, err)
53+
_, err = c.CreateUser(ctx, codersdk.CreateUserRequest{
54+
Email: "test2@coder.com",
55+
Username: "ethan",
56+
Password: "SomeSecurePassword!",
57+
UserLoginType: "password",
58+
DisableLogin: false,
59+
OrganizationID: me.OrganizationIDs[0],
60+
})
61+
assert.NoError(t, err)
62+
},
4963
assertF: func(t testing.TB, c *codersdk.Client) {
5064
// Check user fields.
5165
user, err := c.User(ctx, "dean")
@@ -95,6 +109,7 @@ func TestIntegration(t *testing.T) {
95109
var buf bytes.Buffer
96110
tfCmd.Stdout = &buf
97111
tfCmd.Stderr = &buf
112+
tt.preF(t, client)
98113
if err := tfCmd.Run(); !assert.NoError(t, err) {
99114
t.Logf(buf.String())
100115
}

integration/user-test/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,17 @@ resource "coderd_user" "dean" {
1616
password = "SomeSecurePassword!"
1717
suspended = false
1818
}
19+
20+
data "coderd_user" "ethan" {
21+
username = "ethan"
22+
}
23+
24+
resource "coderd_user" "ethan2" {
25+
username = "${data.coderd_user.ethan.username}2"
26+
name = "${data.coderd_user.ethan.name}2"
27+
email = "${data.coderd_user.ethan.email}.au"
28+
login_type = "${data.coderd_user.ethan.login_type}"
29+
roles = data.coderd_user.ethan.roles
30+
suspended = data.coderd_user.ethan.suspended
31+
}
32+

internal/provider/example_data_source.go

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

internal/provider/example_data_source_test.go

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

internal/provider/provider.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package provider
52

63
import (
@@ -112,7 +109,7 @@ func (p *CoderdProvider) Resources(ctx context.Context) []func() resource.Resour
112109

113110
func (p *CoderdProvider) DataSources(ctx context.Context) []func() datasource.DataSource {
114111
return []func() datasource.DataSource{
115-
NewExampleDataSource,
112+
NewUserDataSource,
116113
}
117114
}
118115

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy