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_group: ensure security/mail enabled groups are excluded when explicitly false in config #841

Merged
merged 2 commits into from
Jul 12, 2022
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: 2 additions & 2 deletions internal/services/groups/group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ func groupDataSourceRead(ctx context.Context, d *schema.ResourceData, meta inter
}

var mailEnabled, securityEnabled *bool
if v, exists := d.GetOk("mail_enabled"); exists {
if v, exists := d.GetOkExists("mail_enabled"); exists { //nolint:staticcheck // needed to detect unset booleans
mailEnabled = utils.Bool(v.(bool))
}
if v, exists := d.GetOk("security_enabled"); exists {
if v, exists := d.GetOkExists("security_enabled"); exists { //nolint:staticcheck // needed to detect unset booleans
securityEnabled = utils.Bool(v.(bool))
}

Expand Down
27 changes: 26 additions & 1 deletion internal/services/groups/group_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ func TestAccGroupDataSource_byDisplayNameWithSecurity(t *testing.T) {
})
}

func TestAccGroupDataSource_byDisplayNameWithSecurityNotMail(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azuread_group", "test")

data.DataSourceTest(t, []resource.TestStep{
{
Config: GroupDataSource{}.displayNameSecurityNotMail(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("display_name").HasValue(fmt.Sprintf("acctestGroup-%d", data.RandomInteger)),
),
},
})
}

func TestAccGroupDataSource_byCaseInsensitiveDisplayName(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azuread_group", "test")

Expand Down Expand Up @@ -153,12 +166,24 @@ func (GroupDataSource) displayNameSecurity(data acceptance.TestData) string {

data "azuread_group" "test" {
display_name = azuread_group.test.display_name
mail_enabled = false
security_enabled = true
}
`, GroupResource{}.basic(data))
}

func (GroupDataSource) displayNameSecurityNotMail(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
%[2]s

data "azuread_group" "test" {
display_name = azuread_group.test.display_name
mail_enabled = false
security_enabled = true
}
`, GroupResource{}.basic(data), GroupResource{}.basicUnified(data))
}

func (GroupDataSource) caseInsensitiveDisplayName(data acceptance.TestData) string {
return fmt.Sprintf(`
%[1]s
Expand Down
4 changes: 2 additions & 2 deletions internal/services/groups/group_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestAccGroup_basic(t *testing.T) {
}

func TestAccGroup_basicUnified(t *testing.T) {
data := acceptance.BuildTestData(t, "azuread_group", "test")
data := acceptance.BuildTestData(t, "azuread_group", "test_unified")
r := GroupResource{}

data.ResourceTest(t, r, []resource.TestStep{
Expand Down Expand Up @@ -485,7 +485,7 @@ resource "azuread_group" "test" {

func (GroupResource) basicUnified(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azuread_group" "test" {
resource "azuread_group" "test_unified" {
display_name = "acctestGroup-%[1]d"
types = ["Unified"]
mail_enabled = true
Expand Down