Skip to content

Commit

Permalink
Cleanup script update
Browse files Browse the repository at this point in the history
  • Loading branch information
gcasilva committed Nov 22, 2023
1 parent 18d8913 commit c27eeb2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/cleanup_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@
"Filter" : "sra-execution",
"Account" : "audit"
},
{
"Type" : "IAM_ROLE",
"Filter" : "sra-management-account-parameters-lambda"
},
{
"Type" : "STACK_SET",
"Filter" : "sra-stackset-execution-role"
Expand Down
5 changes: 5 additions & 0 deletions scripts/cleanup_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,12 @@ def delete_iam_role(item):
for policy in policies['AttachedPolicies']:
print(f"..Detaching policy {policy['PolicyArn']} from role {role_name}.")
iam_session.detach_role_policy(RoleName=role_name, PolicyArn=policy['PolicyArn'])
policies = iam_session.list_role_policies(RoleName=role_name)
for policy in policies['PolicyNames']:
print(f"..Deleting inline policy {policy} from role {role_name}.")
iam_session.delete_role_policy(RoleName=role_name, PolicyName=policy)
print(f"....Deleting role {role_name}.")
iam_session
iam_session.delete_role(RoleName=role_name)
except Exception as exe:
if exe.response['Error']['Code'] == 'NoSuchEntity':
Expand Down

0 comments on commit c27eeb2

Please sign in to comment.