def module_deploy_common_settings()

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


def module_deploy_common_settings(action, module_name, setup_path, varcontents, projid, tfbucket):
    # Get Terraform Bucket Details
    if tfbucket is None:
        tfbucket = getbucket(action, projid)
    print("\nGCS bucket for Terraform config & state (Selected) : " + Fore.GREEN + Style.BRIGHT + tfbucket + Style.RESET_ALL)

    # Setting Org ID, Billing Account, Folder ID
    if (action == ACTION_CREATE_DEPLOYMENT):

        # Check for any overides of basic inputs from terraform.tfvars file
        orgid, billing_acc, folderid, randomid = check_basic_inputs_tfvars(varcontents)

        # Getting Base Inputs
        orgid, billing_acc, folderid, randomid = basic_input(orgid, billing_acc, folderid, randomid)

        # Set environment path as deployment directory
        prefix = module_name + '_' + randomid
        env_path = setup_path + '/deployments/' + prefix

        # Checking if 'deployment' folder exist in local. If YES, delete the same.
        delifexist(env_path)

        # Copy module directory
        shutil.copytree(os.path.dirname(os.getcwd()) + '/modules/' + module_name, env_path)

        # Set Terraform states remote backend as GCS
        settfstategcs(env_path, prefix, tfbucket, projid)

        # Create file with billing/org/folder details
        create_tfvars(env_path, varcontents)

        # Create file with billing/org/folder details
        create_env(env_path, orgid, billing_acc, folderid)

        print("\nCREATING DEPLOYMENT...")

        return env_path, tfbucket, orgid, billing_acc, folderid, randomid

    elif (action == ACTION_UPDATE_DEPLOYMENT or action == ACTION_DELETE_DEPLOYMENT):

        # List Existing Deployments
        list_radlab_deployments(tfbucket, module_name, projid)

        # Get Deployment ID
        randomid = input(Fore.YELLOW + Style.BRIGHT + "\nEnter RAD Lab Module Deployment ID (example 'l8b3' is the id for module deployment with name - data_science_l8b3)" + Style.RESET_ALL + ': ')
        randomid = randomid.strip()

        # Validating Deployment ID
        if (len(randomid) == 4 and randomid.isalnum()):

            # Set environment path as deployment directory
            prefix = module_name + '_' + randomid
            env_path = setup_path + '/deployments/' + prefix

            # Setting Local Deployment
            setlocaldeployment(tfbucket, prefix, env_path, projid)

        else:
            sys.exit(Fore.RED + "\nInvalid deployment ID!\n")

        # Get env values
        orgid, billing_acc, folderid = get_env(env_path)

        # Set Terraform states remote backend as GCS
        settfstategcs(env_path, prefix, tfbucket, projid)

        # Create file with billing/org/folder details and user input variables
        if os.path.exists(env_path + '/terraform.tfvars'):
            os.remove(env_path + '/terraform.tfvars')
        create_tfvars(env_path, varcontents)

        if (action == ACTION_UPDATE_DEPLOYMENT):
            print("\nUPDATING DEPLOYMENT...")

        if (action == ACTION_DELETE_DEPLOYMENT):
            print("\nDELETING DEPLOYMENT...")

        return env_path, tfbucket, orgid, billing_acc, folderid, randomid

    elif (action == ACTION_LIST_DEPLOYMENT):
        list_radlab_deployments(tfbucket, module_name, projid)
        sys.exit()

    else:
        sys.exit(Fore.RED + "\nInvalid RAD Lab Module Action selected")