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_groups: support empty list for names/object_ids arguments #257

Merged
merged 2 commits 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
4 changes: 0 additions & 4 deletions azuread/data_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func dataGroups() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Computed: true,
MinItems: 1,
ConflictsWith: []string{"names"},
Elem: &schema.Schema{
Type: schema.TypeString,
Expand All @@ -38,7 +37,6 @@ func dataGroups() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Computed: true,
MinItems: 1,
ConflictsWith: []string{"object_ids"},
Elem: &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -75,8 +73,6 @@ func dataSourceGroupsRead(d *schema.ResourceData, meta interface{}) error {

groups = append(groups, resp)
}
} else {
return fmt.Errorf("one of `object_ids` or `names` must be supplied")
}

if len(groups) != expectedCount {
Expand Down
25 changes: 25 additions & 0 deletions azuread/data_groups_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ func TestAccAzureADGroupsDataSource_byObjectIds(t *testing.T) {
})
}

func TestAccAzureADGroupsDataSource_noNames(t *testing.T) {
dsn := "data.azuread_groups.test"

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

func testAccAzureADGroup_multiple(id int) string {
return fmt.Sprintf(`
resource "azuread_group" "testA" {
Expand Down Expand Up @@ -80,3 +98,10 @@ data "azuread_groups" "test" {
}
`, testAccAzureADGroup_multiple(id))
}
func testAccAzureADGroupsDataSource_noNames() string {
return `
data "azuread_groups" "test" {
names = []
}
`
}
4 changes: 2 additions & 2 deletions website/docs/d/groups.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ data "azuread_groups" "groups" {

The following arguments are supported:

* `names` - (optional) The Display Names of the Azure AD Groups.
* `names` - (Optional) The Display Names of the Azure AD Groups.

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

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

## Attributes Reference

Expand Down