def scan_provisioned_products()

in lambdas/stepfunctions/CTE_CreateAccountFn/src/helper.py [0:0]


def scan_provisioned_products(search_pp_name, client: boto3.client) -> dict:
    """Search for existing Service Catalog Provisioned Products

    Args:
        search_pp_name (str): Service Catalog Provisioned Product Name to search for
        client (boto3.client): Boto3 Client for Service Catalog

    Returns:
        str: Service Catalog Provisioned
    """
    logger.info('Making sure Control Tower is not already executing')
    paginator = client.get_paginator("scan_provisioned_products")
    for page in paginator.paginate(
            AccessLevelFilter={
                'Key': 'Account',
                'Value': 'self'
            }
    ):
        for x in page['ProvisionedProducts']:
            if x['Type'] == 'CONTROL_TOWER_ACCOUNT':

                # Since Control Tower has a serial method of deploying account this statement will check to see if
                #  there's and existing In-Progress deployment and will return provision the product name / status
                if x['Status'] == 'UNDER_CHANGE' and x['Name'] != search_pp_name:
                    logger.info(f"Found In-Progress Control Tower Deployment ({x['Name']})")
                    return {"ProvisionedProductName": x['Name'], "Status": x['Status']}

                # If existing provision product found return
                elif x['Name'] == search_pp_name:
                    logger.info(f"Found {x}")

                    # Removing Create time since it doesn't serializable JSON well
                    del x['CreatedTime']
                    return x