def run(dry_run,
        print_to_file=None,
        enable_deletion=False,
        io_dir='throughput/',
        thread_pool_size=10,
        send_mails=True):
    # setup errors should skip resources that will lead
    # to terraform errors. we should still do our best
    # to reconcile all valid resources for all accounts.
    accounts, working_dirs, setup_err, aws_api = setup(print_to_file,
                                                       thread_pool_size)
    if print_to_file:
        cleanup_and_exit()
    if not working_dirs:
        err = True
        cleanup_and_exit(status=err)

    tf = Terraform(QONTRACT_INTEGRATION,
                   QONTRACT_INTEGRATION_VERSION,
                   QONTRACT_TF_PREFIX,
                   accounts,
                   working_dirs,
                   thread_pool_size,
                   aws_api,
                   init_users=True)
    if tf is None:
        err = True
        cleanup_and_exit(tf, err)

    disabled_deletions_detected, err = tf.plan(enable_deletion)
    if err:
        cleanup_and_exit(tf, err)
    tf.dump_deleted_users(io_dir)
    if disabled_deletions_detected:
        cleanup_and_exit(tf, disabled_deletions_detected)

    if dry_run:
        cleanup_and_exit(tf, setup_err)

    err = tf.apply()
    if err:
        cleanup_and_exit(tf, err)

    if send_mails:
        new_users = tf.get_new_users()
        settings = queries.get_app_interface_settings()
        send_email_invites(new_users, settings)

    cleanup_and_exit(tf, setup_err)
def run(dry_run,
        print_to_file=None,
        enable_deletion=False,
        io_dir='throughput/',
        thread_pool_size=10,
        send_mails=True):
    accounts, working_dirs = setup(print_to_file, thread_pool_size)
    if print_to_file:
        cleanup_and_exit()
    if working_dirs is None:
        err = True
        cleanup_and_exit(status=err)

    tf = Terraform(QONTRACT_INTEGRATION,
                   QONTRACT_INTEGRATION_VERSION,
                   QONTRACT_TF_PREFIX,
                   accounts,
                   working_dirs,
                   thread_pool_size,
                   init_users=True)
    if tf is None:
        err = True
        cleanup_and_exit(tf, err)

    disabled_deletions_detected, err = tf.plan(enable_deletion)
    if err:
        cleanup_and_exit(tf, err)
    tf.dump_deleted_users(io_dir)
    if disabled_deletions_detected:
        cleanup_and_exit(tf, disabled_deletions_detected)

    if dry_run:
        cleanup_and_exit(tf)

    err = tf.apply()
    if err:
        cleanup_and_exit(tf, err)

    if send_mails:
        new_users = tf.get_new_users()
        settings = queries.get_app_interface_settings()
        send_email_invites(new_users, settings)

    cleanup_and_exit(tf)