def env()

in radlab-launcher/radlab.py [0:0]


def env(action, orgid, billing_acc, folderid, env_path, deployment_id, tfbucket, projid):
    tr = Terraform(working_dir=env_path)
    return_code, stdout, stderr = tr.init_cmd(capture_output=False)

    if (action == ACTION_CREATE_DEPLOYMENT or action == ACTION_UPDATE_DEPLOYMENT):
        return_code, stdout, stderr = tr.apply_cmd(capture_output=False, auto_approve=True, var={'organization_id': orgid, 'billing_account_id': billing_acc, 'deployment_id': deployment_id})
        return_code, stdout, stderr = tr.apply_cmd(refresh=True, capture_output=False, auto_approve=True, var={'organization_id': orgid, 'billing_account_id': billing_acc, 'deployment_id': deployment_id})

    elif (action == ACTION_DELETE_DEPLOYMENT):
        return_code, stdout, stderr = tr.destroy_cmd(capture_output=False, auto_approve=True, var={'organization_id': orgid, 'billing_account_id': billing_acc, 'deployment_id': deployment_id})

    # return_code - 0 Success & 1 Error
    if (return_code == 1):
        print(stderr)
        sys.exit(Fore.RED + Style.BRIGHT + "\nError Occured - Deployment failed for ID: " + deployment_id + "\n" + "Retry using above Deployment ID" + Style.RESET_ALL)
    else:
        target_path = 'radlab/' + env_path.split('/')[len(env_path.split('/')) - 1] + '/deployments'

        if (action == ACTION_CREATE_DEPLOYMENT or action == ACTION_UPDATE_DEPLOYMENT):

            if glob.glob(env_path + '/*.tf'):
                upload_from_directory(projid, env_path, '/*.tf', tfbucket, target_path)
            if glob.glob(env_path + '/*.json'):
                upload_from_directory(projid, env_path, '/*.json', tfbucket, target_path)
            if glob.glob(env_path + '/elk'):
                upload_from_directory(projid, env_path, '/elk/**', tfbucket, target_path)
            if glob.glob(env_path + '/scripts'):
                upload_from_directory(projid, env_path, '/scripts/**', tfbucket, target_path)
            if glob.glob(env_path + '/templates'):
                upload_from_directory(projid, env_path, '/templates/**', tfbucket, target_path)

        elif (action == ACTION_DELETE_DEPLOYMENT):
            deltfgcs(tfbucket, 'radlab/' + env_path.split('/')[len(env_path.split('/')) - 1], projid)

    # Deleting Local deployment config
    shutil.rmtree(env_path)