Skip to content

Commit

Permalink
Merge pull request #2983 from handlerbot/fix-iam-profile-delete
Browse files Browse the repository at this point in the history
resource/aws_iam_instance_profile: Fix bug preventing destruction with -refresh…
  • Loading branch information
radeksimko authored Jan 17, 2018
2 parents 127a630 + 606a88c commit 0979fc3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion aws/resource_aws_iam_instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,20 @@ func instanceProfileSetRoles(d *schema.ResourceData, iamconn *iam.IAM) error {
}

func instanceProfileRemoveAllRoles(d *schema.ResourceData, iamconn *iam.IAM) error {
for _, role := range d.Get("roles").(*schema.Set).List() {
role, hasRole := d.GetOk("role")
roles, hasRoles := d.GetOk("roles")
if hasRole && !hasRoles { // "roles" will always be a superset of "role", if set
err := instanceProfileRemoveRole(iamconn, d.Id(), role.(string))
if err != nil {
return fmt.Errorf("Error removing role %s from IAM instance profile %s: %s", role, d.Id(), err)
}
} else {
for _, role := range roles.(*schema.Set).List() {
err := instanceProfileRemoveRole(iamconn, d.Id(), role.(string))
if err != nil {
return fmt.Errorf("Error removing role %s from IAM instance profile %s: %s", role, d.Id(), err)
}
}
}
return nil
}
Expand Down

0 comments on commit 0979fc3

Please sign in to comment.