From 4f915427130e2b55bad62a4e68a720d901c6f368 Mon Sep 17 00:00:00 2001 From: Matthew Riley Date: Fri, 19 Jan 2018 23:24:54 -0800 Subject: [PATCH] Replace Pulumi "role" fix with one from upstream https://github.com/pulumi/terraform-provider-aws/pull/5 obsoleted by https://github.com/terraform-providers/terraform-provider-aws/pull/2983 --- aws/resource_aws_iam_instance_profile.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/aws/resource_aws_iam_instance_profile.go b/aws/resource_aws_iam_instance_profile.go index a738be304a0..837a3a51325 100644 --- a/aws/resource_aws_iam_instance_profile.go +++ b/aws/resource_aws_iam_instance_profile.go @@ -210,23 +210,19 @@ func instanceProfileSetRoles(d *schema.ResourceData, iamconn *iam.IAM) error { } func instanceProfileRemoveAllRoles(d *schema.ResourceData, iamconn *iam.IAM) error { - removedSingleRole := "" - if role, ok := d.GetOk("role"); ok { + 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) } - removedSingleRole = role.(string) - } - - for _, role := range d.Get("roles").(*schema.Set).List() { - if role.(string) == removedSingleRole { - continue - } - - 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