in functions/source/c1c_controltower_lifecycle.py [0:0]
def configure_account(aws_account_id):
c1c_connector = c1cconnectorapi.CloudOneConformityConnector(
c1cresources.get_api_key()
)
sts_client = boto3.client("sts")
sts_identity = sts_client.get_caller_identity()
partition = sts_identity["Arn"].split(":")[1]
iam_client = boto3.client("iam")
try:
logger.info("Create Connector Object")
logger.info("Create role in target account")
create_cross_account_role(aws_account_id, c1c_connector)
except iam_client.exceptions.EntityAlreadyExistsException as e:
update_policy(aws_account_id)
except Exception as e:
logger.error(
f"Failed to configure account {aws_account_id} with exception: {e}"
)
# Wait for eventual consistency to become consistent
time.sleep(20)
logger.info("Add account to Cloud One Conformity")
try:
return c1c_connector.add_account(
f"arn:{partition}:iam::{aws_account_id}:role/{c1cresources.IamRoleName}"
)
except Exception as e:
logger.error(f"Failed to add conformity connector with exception {e}")