-
Notifications
You must be signed in to change notification settings - Fork 2
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 resource #18
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Resource - coderd" | ||
subcategory: "" | ||
description: |- | ||
A user on the Coder deployment. | ||
--- | ||
|
||
# coderd_user (Resource) | ||
|
||
A user on the Coder deployment. | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `email` (String) Email address of the user. | ||
- `username` (String) Username of the user. | ||
|
||
### Optional | ||
|
||
- `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. | ||
- `password` (String, Sensitive) Password for the user. Required when login_type is 'password'. Passwords are saved into the state as plain text and should only be used for testing purposes. | ||
- `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. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) User ID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"net" | ||
"net/url" | ||
"os" | ||
|
@@ -15,6 +16,7 @@ import ( | |
|
||
"github.com/coder/coder/v2/codersdk" | ||
"github.com/docker/docker/api/types/container" | ||
"github.com/docker/docker/api/types/image" | ||
"github.com/docker/docker/client" | ||
"github.com/docker/go-connections/nat" | ||
"github.com/stretchr/testify/assert" | ||
|
@@ -50,11 +52,33 @@ func TestIntegration(t *testing.T) { | |
assertF func(testing.TB, *codersdk.Client) | ||
}{ | ||
{ | ||
name: "example-test", | ||
name: "user-test", | ||
assertF: func(t testing.TB, c *codersdk.Client) { | ||
me, err := c.User(ctx, codersdk.Me) | ||
// Check user fields. | ||
user, err := c.User(ctx, "dean") | ||
assert.NoError(t, err) | ||
assert.NotEmpty(t, me) | ||
assert.Equal(t, "dean", user.Username) | ||
assert.Equal(t, "Dean Coolguy", user.Name) | ||
assert.Equal(t, "[email protected]", user.Email) | ||
roles := make([]string, len(user.Roles)) | ||
for i, role := range user.Roles { | ||
roles[i] = role.Name | ||
} | ||
assert.ElementsMatch(t, []string{"owner", "template-admin"}, roles) | ||
assert.Equal(t, codersdk.LoginTypePassword, user.LoginType) | ||
assert.Contains(t, []codersdk.UserStatus{codersdk.UserStatusActive, codersdk.UserStatusDormant}, user.Status) | ||
|
||
// Test password. | ||
newClient := codersdk.New(c.URL) | ||
res, err := newClient.LoginWithPassword(ctx, codersdk.LoginWithPasswordRequest{ | ||
Email: "[email protected]", | ||
Password: "SomeSecurePassword!", | ||
}) | ||
assert.NoError(t, err) | ||
newClient.SetSessionToken(res.SessionToken) | ||
user, err = newClient.User(ctx, codersdk.Me) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "dean", user.Username) | ||
}, | ||
}, | ||
} { | ||
|
@@ -63,6 +87,14 @@ func TestIntegration(t *testing.T) { | |
wd, err := os.Getwd() | ||
require.NoError(t, err) | ||
srcDir := filepath.Join(wd, tt.name) | ||
// Delete all .tfstate files | ||
err = filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error { | ||
if filepath.Ext(path) == ".tfstate" { | ||
return os.Remove(path) | ||
} | ||
return nil | ||
}) | ||
require.NoError(t, err) | ||
tfCmd := exec.CommandContext(ctx, "terraform", "-chdir="+srcDir, "apply", "-auto-approve") | ||
tfCmd.Env = append(tfCmd.Env, "TF_CLI_CONFIG_FILE="+tfrcPath) | ||
tfCmd.Env = append(tfCmd.Env, "CODER_URL="+client.URL.String()) | ||
|
@@ -124,6 +156,11 @@ func startCoder(ctx context.Context, t *testing.T, name string) *codersdk.Client | |
p := randomPort(t) | ||
t.Logf("random port is %d", p) | ||
// Stand up a temporary Coder instance | ||
puller, err := cli.ImagePull(ctx, coderImg+":"+coderVersion, image.PullOptions{}) | ||
require.NoError(t, err, "pull coder image") | ||
defer puller.Close() | ||
_, err = io.Copy(os.Stderr, puller) | ||
require.NoError(t, err, "pull coder image") | ||
ctr, err := cli.ContainerCreate(ctx, &container.Config{ | ||
Image: coderImg + ":" + coderVersion, | ||
Env: []string{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
terraform { | ||
required_providers { | ||
coderd = { | ||
source = "coder/coderd" | ||
version = ">=0.0.0" | ||
} | ||
} | ||
} | ||
|
||
resource "coderd_user" "dean" { | ||
username = "dean" | ||
name = "Dean Coolguy" | ||
email = "[email protected]" | ||
roles = ["owner", "template-admin"] | ||
login_type = "password" | ||
password = "SomeSecurePassword!" | ||
suspended = false | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, it just seems like these integration tests accomplish the same thing as the acceptance test in
user_resource_test.go
, yet they're way more complicated. I think the integration tests probably make more sense for chaining resources together or something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unclear from your comment what you want to happen. Do you want us to use the integration tests or the resource tests? The resource tests will take effort to get working (most likely some mocking stuff, and we might not be able to use the hashi test framework)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like you could easily start a coderd pod in the resource tests similar to whats going on here and accomplish the same thing without having to mock anything. It also doesn't seem like we're testing read/update/delete/import here either, which the resource test just has natively. We're also not able to assert any of the terraform state here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, can we do that in a follow up though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to start a
coderd
pod for acceptance tests, why not just importcoderdtest
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's not much of a difference, but running a container is better because it auto updates for us lol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah plus we'll need to copy the gomod replaces and keeping that in sync seems like more of a headache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah agreed that's super annoying, let's not do that