Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 5bfe3e2

Browse files
author
Florian Zeidler
committed
Remove all versions of a policy, too.
1 parent c164e96 commit 5bfe3e2

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

resources/iam-policies.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,25 @@ func (n *IamNuke) ListPolicies() ([]Resource, error) {
3030
}
3131

3232
func (e *IamPolicy) Remove() error {
33-
_, err := e.svc.DeletePolicy(&iam.DeletePolicyInput{
33+
resp, err := e.svc.ListPolicyVersions(&iam.ListPolicyVersionsInput{
34+
PolicyArn: &e.arn,
35+
})
36+
if err != nil {
37+
return err
38+
}
39+
for _, version := range resp.Versions {
40+
if !*version.IsDefaultVersion {
41+
_, err = e.svc.DeletePolicyVersion(&iam.DeletePolicyVersionInput{
42+
PolicyArn: &e.arn,
43+
VersionId: version.VersionId,
44+
})
45+
if err != nil {
46+
return err
47+
}
48+
49+
}
50+
}
51+
_, err = e.svc.DeletePolicy(&iam.DeletePolicyInput{
3452
PolicyArn: &e.arn,
3553
})
3654
if err != nil {

0 commit comments

Comments
 (0)