check length of slices instead of using incorrect type

This commit is contained in:
Patrick Gray 2015-06-28 20:00:55 -04:00
parent c375a72f15
commit 0f5c9c012d
1 changed files with 11 additions and 4 deletions

View File

@ -58,7 +58,7 @@ func resourceAwsIamPolicyAttachmentCreate(d *schema.ResourceData, meta interface
roles := expandStringList(d.Get("roles").(*schema.Set).List())
groups := expandStringList(d.Get("groups").(*schema.Set).List())
if users == "" && roles == "" && groups == "" {
if len(users) > 0 && len(roles) > 0 && len(groups) > 0 {
return fmt.Errorf("[WARN] No Users, Roles, or Groups specified for %s", name)
} else {
var userErr, roleErr, groupErr error
@ -161,13 +161,13 @@ func resourceAwsIamPolicyAttachmentDelete(d *schema.ResourceData, meta interface
groups := expandStringList(d.Get("groups").(*schema.Set).List())
var userErr, roleErr, groupErr error
if users != "" {
if len(users) != 0 {
userErr = detachPolicyFromUsers(conn, users, arn)
}
if roles != "" {
if len(roles) != 0 {
roleErr = detachPolicyFromRoles(conn, roles, arn)
}
if groups != "" {
if len(groups) != 0 {
groupErr = detachPolicyFromGroups(conn, groups, arn)
}
if userErr != nil || roleErr != nil || groupErr != nil {
@ -175,6 +175,13 @@ func resourceAwsIamPolicyAttachmentDelete(d *schema.ResourceData, meta interface
}
return nil
}
//func composeErrors(desc string, uErr error, rErr error, gErr error) error {
// errMsg := fmt.Sprintf(desc)
// errs := []error{uErr, rErr, gErr}
// return nil
//}
func attachPolicyToUsers(conn *iam.IAM, users []*string, arn string) error {
for _, u := range users {
_, err := conn.AttachUserPolicy(&iam.AttachUserPolicyInput{