Skip to content

Commit

Permalink
Merge pull request #4209 from spirius/feature/iam-role-suppress-detac…
Browse files Browse the repository at this point in the history
…h-error

resource/aws_iam_role: Suppress NoSuchEntity errors while detaching policies from role
  • Loading branch information
bflad authored Apr 17, 2018
2 parents bd7811d + 9db8731 commit 983d10e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions aws/resource_aws_iam_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"log"
"net/url"
"regexp"
"time"
Expand Down Expand Up @@ -317,7 +318,11 @@ func resourceAwsIamRoleDelete(d *schema.ResourceData, meta interface{}) error {
RoleName: aws.String(d.Id()),
})
if err != nil {
return fmt.Errorf("Error deleting IAM Role %s: %s", d.Id(), err)
if isAWSErr(err, iam.ErrCodeNoSuchEntityException, "") {
log.Printf("[WARN] Role policy attachment (%s) was already removed from role (%s)", aws.StringValue(parn), d.Id())
} else {
return fmt.Errorf("Error deleting IAM Role %s: %s", d.Id(), err)
}
}
}
}
Expand All @@ -342,7 +347,11 @@ func resourceAwsIamRoleDelete(d *schema.ResourceData, meta interface{}) error {
RoleName: aws.String(d.Id()),
})
if err != nil {
return fmt.Errorf("Error deleting inline policy of IAM Role %s: %s", d.Id(), err)
if isAWSErr(err, iam.ErrCodeNoSuchEntityException, "") {
log.Printf("[WARN] Inline role policy (%s) was already removed from role (%s)", aws.StringValue(pname), d.Id())
} else {
return fmt.Errorf("Error deleting inline policy of IAM Role %s: %s", d.Id(), err)
}
}
}
}
Expand Down

0 comments on commit 983d10e

Please sign in to comment.