provider/aws: Query all pages of group membership

By default, group membership queries return pages of 100 users at a
time. Because of this, if there are more than 100 users in an
aws_iam_group_membership resource, the resource always reports as
needing to be changed (because it only sees 100 of the users as
existing in the group).

The group membership now queries all pages.

Fixes #6722
This commit is contained in:
Mark Severson 2016-05-17 14:23:05 -06:00
parent d3b0a301c7
commit 0315d51125
1 changed files with 25 additions and 15 deletions

View File

@ -56,8 +56,13 @@ func resourceAwsIamGroupMembershipCreate(d *schema.ResourceData, meta interface{
func resourceAwsIamGroupMembershipRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).iamconn
group := d.Get("group").(string)
var ul []string
var marker *string
for {
resp, err := conn.GetGroup(&iam.GetGroupInput{
GroupName: aws.String(group),
Marker: marker,
})
if err != nil {
@ -72,11 +77,16 @@ func resourceAwsIamGroupMembershipRead(d *schema.ResourceData, meta interface{})
return err
}
ul := make([]string, 0, len(resp.Users))
for _, u := range resp.Users {
ul = append(ul, *u.UserName)
}
if !*resp.IsTruncated {
break
}
marker = resp.Marker
}
if err := d.Set("users", ul); err != nil {
return fmt.Errorf("[WARN] Error setting user list from IAM Group Membership (%s), error: %s", group, err)
}