Skip to content

Commit

Permalink
Merge pull request #258 from terraform-providers/data.users/support-e…
Browse files Browse the repository at this point in the history
…mpty-lists

 data.azuread_users: support empty search lists
  • Loading branch information
manicminer authored May 29, 2020
2 parents 8579ea8 + 031e3dc commit c1b24af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
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

0 comments on commit c1b24af

Please sign in to comment.