in src/org_setup/resources/organizations.py [0:0]
def attach_ai_optout_policy(self) -> None:
"""
Attach the AI opt-out policy to the root
"""
policy_id = self.get_ai_optout_policy()
if not policy_id:
logger.warn(
f"[{self.region}] Unable to find {AI_OPT_OUT_POLICY_NAME} policy"
)
return
for root in self.list_roots():
root_id = root["Id"]
logger.info(
f"[{self.region}] Attaching {AI_OPT_OUT_POLICY_NAME} ({policy_id}) to root {root_id}"
)
try:
self.client.attach_policy(PolicyId=policy_id, TargetId=root_id)
logger.debug(
f"[{self.region}] Attached {AI_OPT_OUT_POLICY_NAME} ({policy_id}) to root {root_id}"
)
except botocore.exceptions.ClientError as error:
if (
error.response["Error"]["Code"]
!= "DuplicatePolicyAttachmentException"
):
logger.exception(f"[{self.region}] Unable to attach policy")
raise error