Skip to content

Commit

Permalink
Catches errors relating to attempting to attach policies to entities …
Browse files Browse the repository at this point in the history
…where they are already attached.
  • Loading branch information
rmc3 committed May 30, 2018
1 parent d868d59 commit eb36974
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cumulogenesis/services/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ def update_entity_policy_attachments(self, org_model, target_id, old_policies, n
if policy not in old_policies:
logger.info('Adding policy association for %s to target %s', policy, target_id)
policy_id = org_model.updated_model.policies[policy]['id']
self.client.attach_policy(PolicyId=policy_id, TargetId=target_id)
try:
self.client.attach_policy(PolicyId=policy_id, TargetId=target_id)
except botocore.exceptions.ClientError as err:
if 'DuplicatePolicyAttachmentException' in str(err):
logger.warning('Policy %s is already attached to target %s', policy, target_id)
else:
raise
for policy in old_policies:
if policy not in new_policies:
logger.info('Removing policy association for %s to target %s', policy, target_id)
Expand Down

0 comments on commit eb36974

Please sign in to comment.