Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LiveLabs autodetect v1 #58

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions basis/bin/auto_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ if [ "$TF_VAR_db_password" == "__TO_FILL__" ]; then
echo "> TF_VAR_db_password=$TF_VAR_db_password"
fi

# Livelabs Green Button (Autodetect compartment/vcn/subnet)
livelabs_green_button

# -- env.sh
# Do not stop if __TO_FILL__ are not replaced if TF_VAR_group_name exist in env variable
# XXX -> It would be safer to check also for TF_VAR_xxx containing __TO_FILL__ too
Expand Down
64 changes: 64 additions & 0 deletions basis/bin/shared_bash_function.sh
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,70 @@ get_ui_url() {
fi
}

livelabs_green_button() {
# Lot of tests to be sure we are in a empty Green Button LiveLabs
# compartment_ocid still undefined ?
if grep -q '# export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx' $PROJECT_DIR/env.sh; then
# vnc_ocid still undefined ?
if [ "$TF_VAR_vcn_ocid" != "__TO_FILL__" ]; then
# Variables already set
return
fi
# In cloud shell ?
if [ -z $OCI_CLI_CLOUD_SHELL ]; then
return
fi
# Whoami user format ?
if [[ `whoami` =~ ^ll.*_u.* ]]; then
echo "LiveLabs - Green Button - User name in llxxx_uxx format"
else
return
fi
get_user_details
# OCI User name format ?
if [[ $TF_VAR_username =~ ^LL.*-USER$ ]]; then
echo "LiveLabs - Green Button"
else
return
fi

export USER_BASE=`echo "${TF_VAR_username/-USER/}"`
echo USER_BASE=$USER_BASE

export TF_VAR_compartment_ocid=`oci iam compartment list --compartment-id-in-subtree true --all | jq -c -r '.data[] | select(.name | contains("'$USER_BASE'")) | .id'`
echo TF_VAR_compartment_ocid=$TF_VAR_compartment_ocid

if [ "$TF_VAR_compartment_ocid" != "" ]; then
sed -i "s&# export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx&export TF_VAR_compartment_ocid=\"$TF_VAR_compartment_ocid\"&" $PROJECT_DIR/env.sh
echo "TF_VAR_compartment_ocid stored in env.sh"
fi

export TF_VAR_vcn_ocid=`oci network vcn list --compartment-id $TF_VAR_compartment_ocid | jq -c -r '.data[].id'`
echo TF_VAR_vcn_ocid=$TF_VAR_vcn_ocid
if [ "$TF_VAR_vcn_ocid" != "" ]; then
sed -i "s&TF_VAR_vcn_ocid=\"__TO_FILL__\"&TF_VAR_vcn_ocid=\"$TF_VAR_vcn_ocid\"&" $PROJECT_DIR/env.sh
echo "TF_VAR_vcn_ocid stored in env.sh"
fi

export TF_VAR_subnet_ocid=`oci network subnet list --compartment-id $TF_VAR_compartment_ocid | jq -c -r '.data[].id'`
echo TF_VAR_subnet_ocid=$TF_VAR_subnet_ocid
if [ "$TF_VAR_subnet_ocid" != "" ]; then
sed -i "s&TF_VAR_public_subnet_ocid=\"__TO_FILL__\"&TF_VAR_public_subnet_ocid=\"$TF_VAR_subnet_ocid\"&" $PROJECT_DIR/env.sh
sed -i "s&TF_VAR_private_subnet_ocid=\"__TO_FILL__\"&TF_VAR_private_subnet_ocid=\"$TF_VAR_subnet_ocid\"&" $PROJECT_DIR/env.sh
echo "TF_VAR_subnet_ocid stored in env.sh"
# Set the real variables such that the first ./build.sh works too.
export TF_VAR_public_subnet_ocid=$TF_VAR_subnet_ocid
export TF_VAR_private_subnet_ocid=$TF_VAR_subnet_ocid
fi

# LiveLabs support only E4 Shapes
if grep -q '# export TF_VAR_instance_shape=VM.Standard.E4.Flex' $PROJECT_DIR/env.sh; then
sed -i "s&# export TF_VAR_instance_shape=&export TF_VAR_instance_shape=&" $PROJECT_DIR/env.sh
fi

fi
}

create_deployment_in_apigw() {
# Publish the API with an API Deployment to API Gateway
if [ "$APIGW_DEPLOYMENT_OCID" != "" ]; then
Expand Down
6 changes: 6 additions & 0 deletions py_oci_starter.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ def env_sh_contents():
contents.append(' # API Management')
contents.append(' # export APIM_HOST=xxxx-xxx.adb.region.oraclecloudapps.com')
contents.append('')

if params.get('instance_shape') == None:
contents.append(' # Compute Shape')
contents.append(' # export TF_VAR_instance_shape=VM.Standard.E4.Flex')
contents.append('')

contents.append(' # Landing Zone')
contents.append(' # export TF_VAR_lz_appdev_cmp_ocid=$TF_VAR_compartment_ocid')
contents.append(' # export TF_VAR_lz_database_cmp_ocid=$TF_VAR_compartment_ocid')
Expand Down