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

data.azuread_users: support empty search lists #258

Merged
merged 1 commit into from
May 29, 2020
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
5 changes: 0 additions & 5 deletions azuread/data_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func dataUsers() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Computed: true,
MinItems: 1,
ConflictsWith: []string{"user_principal_names"},
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -38,7 +37,6 @@ func dataUsers() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Computed: true,
MinItems: 1,
ConflictsWith: []string{"object_ids"},
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -50,7 +48,6 @@ func dataUsers() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Computed: true,
MinItems: 1,
ConflictsWith: []string{"object_ids", "user_principal_names"},
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -96,8 +93,6 @@ func dataSourceUsersRead(d *schema.ResourceData, meta interface{}) error {
}
users = append(users, *u)
}
} else {
return fmt.Errorf("one of `object_ids`, `user_principal_names` or `mail_nicknames` must be supplied")
}

if len(users) != expectedCount {
Expand Down
27 changes: 27 additions & 0 deletions azuread/data_users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ func TestAccAzureADUsersDataSource_byMailNicknames(t *testing.T) {
})
}

func TestAccAzureADUsersDataSource_noNames(t *testing.T) {
dsn := "data.azuread_users.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccAzureADUsersDataSource_noNames(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dsn, "user_principal_names.#", "0"),
resource.TestCheckResourceAttr(dsn, "object_ids.#", "0"),
resource.TestCheckResourceAttr(dsn, "mail_nicknames.#", "0"),
),
},
},
})
}

func testAccAzureADUsersDataSource_byUserPrincipalNames(id int, password string) string {
return fmt.Sprintf(`
%s
Expand Down Expand Up @@ -100,3 +119,11 @@ data "azuread_users" "test" {
}
`, testAccADUser_threeUsersABC(id, password))
}

func testAccAzureADUsersDataSource_noNames() string {
return `
data "azuread_users" "test" {
user_principal_names = []
}
`
}
4 changes: 2 additions & 2 deletions website/docs/d/users.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ data "azuread_users" "users" {

The following arguments are supported:

* `user_principal_names` - (optional) The User Principal Names of the Azure AD Users.
* `user_principal_names` - (Optional) The User Principal Names of the Azure AD Users.

* `object_ids` - (Optional) The Object IDs of the Azure AD Users.

* `mail_nicknames` - (Optional) The email aliases of the Azure AD Users.

-> **NOTE:** Either `user_principal_names`, `object_ids` or `mail_nicknames` must be specified.
-> **NOTE:** Either `user_principal_names`, `object_ids` or `mail_nicknames` should be specified. These _may_ be specified as an empty list, in which case no results will be returned.

## Attributes Reference

Expand Down