-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support to search via Lucene query for auth0_user data-source (#…
…1141) * Added support to search via Lucene query for auth0_user data-source * Updated documentation * Improved comments * updated clause
- Loading branch information
1 parent
6fa53f2
commit eff301c
Showing
5 changed files
with
1,862 additions
and
148 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
--- | ||
page_title: "Data Source: auth0_user" | ||
description: |- | ||
Data source to retrieve a specific Auth0 user by user_id. | ||
Data source to retrieve a specific Auth0 user by user_id or by lucene query. If filtered by Lucene Query, it should include sufficient filters to retrieve a unique user. | ||
--- | ||
|
||
# Data Source: auth0_user | ||
|
||
Data source to retrieve a specific Auth0 user by `user_id`. | ||
Data source to retrieve a specific Auth0 user by `user_id` or by `lucene query`. If filtered by Lucene Query, it should include sufficient filters to retrieve a unique user. | ||
|
||
## Example Usage | ||
|
||
|
@@ -15,13 +15,24 @@ Data source to retrieve a specific Auth0 user by `user_id`. | |
data "auth0_user" "my_user" { | ||
user_id = "auth0|34fdr23fdsfdfsf" | ||
} | ||
# An Auth0 User loaded through Lucene query. | ||
data "auth0_user" "my_user" { | ||
query = "email:[email protected]" | ||
} | ||
# An Auth0 User loaded through Lucene query. | ||
data "auth0_user" "my_user" { | ||
query = "username:johndoe" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
### Optional | ||
|
||
- `query` (String) Lucene Query for retrieving a user. | ||
- `user_id` (String) ID of the user. | ||
|
||
### Read-Only | ||
|
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 |
---|---|---|
|
@@ -2,3 +2,13 @@ | |
data "auth0_user" "my_user" { | ||
user_id = "auth0|34fdr23fdsfdfsf" | ||
} | ||
|
||
# An Auth0 User loaded through Lucene query. | ||
data "auth0_user" "my_user" { | ||
query = "email:[email protected]" | ||
} | ||
|
||
# An Auth0 User loaded through Lucene query. | ||
data "auth0_user" "my_user" { | ||
query = "username:johndoe" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ data "auth0_user" "user" { | |
} | ||
` | ||
|
||
const testAccDataSourceUser = ` | ||
const testAccDataSourceUserTemplate = ` | ||
resource "auth0_resource_server" "resource_server" { | ||
name = "Acceptance Test - {{.testName}}" | ||
identifier = "https://uat.api.terraform-provider-auth0.com/{{.testName}}" | ||
|
@@ -97,12 +97,26 @@ resource "auth0_user_roles" "user_roles" { | |
user_id = auth0_user.user.id | ||
roles = [ auth0_role.owner.id, auth0_role.admin.id ] | ||
}` | ||
|
||
const testAccDataSourceUserWithID = testAccDataSourceUserTemplate + ` | ||
data "auth0_user" "test" { | ||
depends_on = [ auth0_user_roles.user_roles ] | ||
user_id = auth0_user.user.id | ||
} | ||
` | ||
|
||
const testAccDataSourceUserWithQueryUsername = testAccDataSourceUserTemplate + ` | ||
data "auth0_user" "test" { | ||
depends_on = [ auth0_user_roles.user_roles ] | ||
query = "username:{{.testName}}" | ||
} | ||
` | ||
|
||
user_id = auth0_user.user.id | ||
const testAccDataSourceUserWithQueryEmail = testAccDataSourceUserTemplate + ` | ||
data "auth0_user" "test" { | ||
depends_on = [ auth0_user_roles.user_roles ] | ||
query = "email:{{.testName}}@acceptance.test.com" | ||
} | ||
` | ||
|
||
|
@@ -116,7 +130,43 @@ func TestAccDataSourceUser(t *testing.T) { | |
ExpectError: regexp.MustCompile(`Error: 404 Not Found: The user does not exist.`), | ||
}, | ||
{ | ||
Config: acctest.ParseTestName(testAccDataSourceUser, testName), | ||
Config: acctest.ParseTestName(testAccDataSourceUserWithID, testName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "email", fmt.Sprintf("%[email protected]", testName)), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "user_id", fmt.Sprintf("auth0|%s", testName)), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "username", testName), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "email", fmt.Sprintf("%[email protected]", testName)), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "name", "Firstname Lastname"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "given_name", "Firstname"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "family_name", "Lastname"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "nickname", testName), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "picture", "https://www.example.com/picture.jpg"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "roles.#", "2"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "permissions.#", "2"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "user_metadata", `{"baz":"qux","foo":"bar"}`), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "app_metadata", `{"baz":"qux","foo":"bar"}`), | ||
), | ||
}, | ||
{ | ||
Config: acctest.ParseTestName(testAccDataSourceUserWithQueryUsername, testName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "email", fmt.Sprintf("%[email protected]", testName)), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "user_id", fmt.Sprintf("auth0|%s", testName)), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "username", testName), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "email", fmt.Sprintf("%[email protected]", testName)), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "name", "Firstname Lastname"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "given_name", "Firstname"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "family_name", "Lastname"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "nickname", testName), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "picture", "https://www.example.com/picture.jpg"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "roles.#", "2"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "permissions.#", "2"), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "user_metadata", `{"baz":"qux","foo":"bar"}`), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "app_metadata", `{"baz":"qux","foo":"bar"}`), | ||
), | ||
}, | ||
{ | ||
Config: acctest.ParseTestName(testAccDataSourceUserWithQueryEmail, testName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "email", fmt.Sprintf("%[email protected]", testName)), | ||
resource.TestCheckResourceAttr("data.auth0_user.test", "user_id", fmt.Sprintf("auth0|%s", testName)), | ||
|
Oops, something went wrong.