Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #166 from garry-jeromson/master
Browse files Browse the repository at this point in the history
Add additional optional user profile attributes
  • Loading branch information
alexkappa authored Feb 3, 2020
2 parents 06b5c78 + 8462b99 commit ff60640
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 15 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,23 @@ In order to test the provider, you can simply run `make test`.
$ make test
```

In order to run the full suite of Acceptance tests, run `make testacc`.

*Note:* Acceptance tests create real resources, and often cost money to run.
In order to run the full suite of Acceptance tests, the following environment variables must be set:

```sh
$ make testacc
AUTH0_DOMAIN=your-tenant.auth0.com
AUTH0_CLIENT_ID=xyz
AUTH0_CLIENT_SECRET=xyz
```

Then, run `make testacc`.

*Note:* The acceptance tests make calls to a real Auth0 tenant, and create real resources. Certain tests, for example
for custom domains (`TestAccCustomDomain`), also require a paid Auth0 subscription to be able to run successfully.

At the time of writing, the following configuration steps are also required for the test tenant:

* The `Username-Password-Authentication` connection must have _Requires Username_ option enabled for the user tests to
succesfully run.



30 changes: 30 additions & 0 deletions auth0/resource_auth0_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ func newUser() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"name": {
Type: schema.TypeString,
Optional: true,
},
"family_name": {
Type: schema.TypeString,
Optional: true,
},
"given_name": {
Type: schema.TypeString,
Optional: true,
},
"nickname": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -83,6 +95,14 @@ func newUser() *schema.Resource {
ValidateFunc: validation.ValidateJsonString,
DiffSuppressFunc: structure.SuppressJsonDiff,
},
"blocked": {
Type: schema.TypeBool,
Optional: true,
},
"picture": {
Type: schema.TypeString,
Optional: true,
},
"roles": {
Type: schema.TypeSet,
Optional: true,
Expand All @@ -107,12 +127,17 @@ func readUser(d *schema.ResourceData, m interface{}) error {

d.Set("user_id", u.ID)
d.Set("username", u.Username)
d.Set("name", u.Name)
d.Set("family_name", u.FamilyName)
d.Set("given_name", u.GivenName)
d.Set("nickname", u.Nickname)
d.Set("email", u.Email)
d.Set("email_verified", u.EmailVerified)
d.Set("verify_email", u.VerifyEmail)
d.Set("phone_number", u.PhoneNumber)
d.Set("phone_verified", u.PhoneVerified)
d.Set("blocked", u.Blocked)
d.Set("picture", u.Picture)

userMeta, err := structure.FlattenJsonToString(u.UserMetadata)
if err != nil {
Expand Down Expand Up @@ -201,13 +226,18 @@ func buildUser(d *schema.ResourceData) (u *management.User, err error) {
u.ID = String(d, "user_id")
u.Connection = String(d, "connection_name")
u.Username = String(d, "username")
u.Name = String(d, "name")
u.FamilyName = String(d, "family_name")
u.GivenName = String(d, "given_name")
u.Nickname = String(d, "nickname")
u.PhoneNumber = String(d, "phone_number")
u.EmailVerified = Bool(d, "email_verified")
u.VerifyEmail = Bool(d, "verify_email")
u.PhoneVerified = Bool(d, "phone_verified")
u.Email = String(d, "email")
u.Password = String(d, "password")
u.Blocked = Bool(d, "blocked")
u.Picture = String(d, "picture")

u.UserMetadata, err = JSON(d, "user_metadata")
if err != nil {
Expand Down
30 changes: 23 additions & 7 deletions auth0/resource_auth0_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ func TestAccUser(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("auth0_user.user", "user_id", "auth0|12345"),
resource.TestCheckResourceAttr("auth0_user.user", "email", "[email protected]"),
resource.TestCheckResourceAttr("auth0_user.user", "nickname", "testnick"),
resource.TestCheckResourceAttr("auth0_user.user", "name", "Firstname Lastname"),
resource.TestCheckResourceAttr("auth0_user.user", "family_name", "Lastname"),
resource.TestCheckResourceAttr("auth0_user.user", "given_name", "Firstname"),
resource.TestCheckResourceAttr("auth0_user.user", "nickname", "some.nickname"),
resource.TestCheckResourceAttr("auth0_user.user", "connection_name", "Username-Password-Authentication"),
resource.TestCheckResourceAttr("auth0_user.user", "roles.#", "0"),
resource.TestCheckResourceAttr("auth0_user.user", "picture", "https://www.example.com/a-valid-picture-url.jpg"),
),
},
{
Expand All @@ -67,11 +71,15 @@ provider auth0 {}
resource auth0_user user {
connection_name = "Username-Password-Authentication"
username = "test"
username = "unique_username"
user_id = "12345"
email = "[email protected]"
password = "passpass$12$12"
nickname = "testnick"
name = "Firstname Lastname"
given_name = "Firstname"
family_name = "Lastname"
nickname = "some.nickname"
picture = "https://www.example.com/a-valid-picture-url.jpg"
user_metadata = <<EOF
{
"foo": "bar",
Expand All @@ -92,11 +100,15 @@ provider auth0 {}
resource auth0_user user {
connection_name = "Username-Password-Authentication"
username = "test"
username = "unique_username"
user_id = "12345"
email = "[email protected]"
password = "passpass$12$12"
nickname = "testnick"
name = "Firstname Lastname"
given_name = "Firstname"
family_name = "Lastname"
nickname = "some.nickname"
picture = "https://www.example.com/a-valid-picture-url.jpg"
roles = [ auth0_role.owner.id, auth0_role.admin.id ]
user_metadata = <<EOF
{
Expand Down Expand Up @@ -128,11 +140,15 @@ provider auth0 {}
resource auth0_user user {
connection_name = "Username-Password-Authentication"
username = "test"
username = "unique_username"
user_id = "12345"
email = "[email protected]"
password = "passpass$12$12"
nickname = "testnick"
name = "Firstname Lastname"
given_name = "Firstname"
family_name = "Lastname"
nickname = "some.nickname"
picture = "https://www.example.com/a-valid-picture-url.jpg"
roles = [ auth0_role.admin.id ]
user_metadata = <<EOF
{
Expand Down
6 changes: 4 additions & 2 deletions example/user/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ provider "auth0" {}
resource "auth0_user" "user" {
connection_name = "Username-Password-Authentication"
user_id = "12345"
username = "test"
nickname = "testnick"
username = "unique_username"
name = "Firstname Lastname"
nickname = "some.nickname"
email = "[email protected]"
email_verified = true
password = "passpass$12$12"
picture = "https://www.example.com/a-valid-picture-url.jpg"
roles = [ auth0_role.admin.id ]
}

Expand Down
7 changes: 5 additions & 2 deletions website/docs/r/user.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ With this resource, you can manage user identities, including resetting password
resource "auth0_user" "user" {
connection_name = "Username-Password-Authentication"
user_id = "12345"
username = "test"
nickname = "testnick"
username = "unique_username"
name = "Firstname Lastname"
given_name = "Firstname"
family_name = "Lastname"
nickname = "some.nickname"
email = "[email protected]"
email_verified = true
password = "passpass$12$12"
Expand Down

0 comments on commit ff60640

Please sign in to comment.