diff --git a/internal/services/groups/group_resource.go b/internal/services/groups/group_resource.go index d5eb2a4479..fd6a06d6a0 100644 --- a/internal/services/groups/group_resource.go +++ b/internal/services/groups/group_resource.go @@ -612,14 +612,14 @@ func groupResourceUpdate(ctx context.Context, d *schema.ResourceData, meta inter return tf.ErrorDiagF(err, "Updating group with ID: %q", d.Id()) } - if v, ok := d.GetOk("members"); ok && d.HasChange("members") { + if d.HasChange("members") { members, _, err := client.ListMembers(ctx, *group.ID) if err != nil { return tf.ErrorDiagF(err, "Could not retrieve members for group with object ID: %q", d.Id()) } existingMembers := *members - desiredMembers := *tf.ExpandStringSlicePtr(v.(*schema.Set).List()) + desiredMembers := *tf.ExpandStringSlicePtr(d.Get("members").(*schema.Set).List()) membersForRemoval := utils.Difference(existingMembers, desiredMembers) membersToAdd := utils.Difference(desiredMembers, existingMembers) diff --git a/internal/services/groups/group_resource_test.go b/internal/services/groups/group_resource_test.go index 46dcca94d6..b1a486b734 100644 --- a/internal/services/groups/group_resource_test.go +++ b/internal/services/groups/group_resource_test.go @@ -562,14 +562,16 @@ resource "azuread_group" "test" { `, r.templateThreeUsers(data), data.RandomInteger) } -func (GroupResource) withNoMembers(data acceptance.TestData) string { +func (r GroupResource) withNoMembers(data acceptance.TestData) string { return fmt.Sprintf(` +%[1]s + resource "azuread_group" "test" { - display_name = "acctestGroup-%[1]d" + display_name = "acctestGroup-%[2]d" security_enabled = true members = [] } -`, data.RandomInteger) +`, r.templateDiverseDirectoryObjects(data), data.RandomInteger) } func (r GroupResource) withOneMember(data acceptance.TestData) string {