From f3a36931015e6e93fa819385d566eca6b2ed1f70 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 20 Nov 2023 17:20:42 +0100 Subject: [PATCH 1/6] v1.6 --- basis/bin/livelabs.sh | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100755 basis/bin/livelabs.sh diff --git a/basis/bin/livelabs.sh b/basis/bin/livelabs.sh new file mode 100755 index 00000000..43e806f4 --- /dev/null +++ b/basis/bin/livelabs.sh @@ -0,0 +1,49 @@ +#!/bin/bash +# +# For LiveLabs only, auto-fill automatically +# - TF_VAR_compartment_ocid, +# - TF_VAR_vcn_ocid +# - TF_VAR_public_subnet_ocid, TF_VAR_private_subnet_ocid +export BIN_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +export PROJECT_DIR=${BIN_DIR%/*} + +# Shared BASH Functions +. $BIN_DIR/shared_bash_function.sh + +if grep -q '# export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx' $PROJECT_DIR/env.sh; then + get_user_details + if [[ $TF_VAR_username =~ ^LL.*-USER$ ]]; then + echo "GREEN BUTTON detected" + else + echo "GREEN BUTTON not detected. Exiting" + exit + 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" + fi +else + echo 'File env.sh does not contain: # export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx' +fi From 3e8405d53d1a1ac982fa3454df1229db778a14e8 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 20 Nov 2023 18:20:21 +0100 Subject: [PATCH 2/6] v1.6 --- basis/bin/livelabs.sh | 49 --------------------- basis/bin/livelabs_green_button.sh | 69 ++++++++++++++++++++++++++++++ basis/bin/shared_bash_function.sh | 59 +++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 49 deletions(-) delete mode 100755 basis/bin/livelabs.sh create mode 100755 basis/bin/livelabs_green_button.sh diff --git a/basis/bin/livelabs.sh b/basis/bin/livelabs.sh deleted file mode 100755 index 43e806f4..00000000 --- a/basis/bin/livelabs.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -# -# For LiveLabs only, auto-fill automatically -# - TF_VAR_compartment_ocid, -# - TF_VAR_vcn_ocid -# - TF_VAR_public_subnet_ocid, TF_VAR_private_subnet_ocid -export BIN_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -export PROJECT_DIR=${BIN_DIR%/*} - -# Shared BASH Functions -. $BIN_DIR/shared_bash_function.sh - -if grep -q '# export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx' $PROJECT_DIR/env.sh; then - get_user_details - if [[ $TF_VAR_username =~ ^LL.*-USER$ ]]; then - echo "GREEN BUTTON detected" - else - echo "GREEN BUTTON not detected. Exiting" - exit - 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" - fi -else - echo 'File env.sh does not contain: # export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx' -fi diff --git a/basis/bin/livelabs_green_button.sh b/basis/bin/livelabs_green_button.sh new file mode 100755 index 00000000..1928f94c --- /dev/null +++ b/basis/bin/livelabs_green_button.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# +# For LiveLabs only, auto-fill automatically +# - TF_VAR_compartment_ocid, +# - TF_VAR_vcn_ocid +# - TF_VAR_public_subnet_ocid, TF_VAR_private_subnet_ocid +export BIN_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +export PROJECT_DIR=${BIN_DIR%/*} + +# Shared BASH Functions +. $BIN_DIR/shared_bash_function.sh + +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" + 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" + fi + else + echo 'File env.sh does not contain: # export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx' + fi +} + +livelabs_green_button \ No newline at end of file diff --git a/basis/bin/shared_bash_function.sh b/basis/bin/shared_bash_function.sh index 32d2e1ab..8815ace6 100755 --- a/basis/bin/shared_bash_function.sh +++ b/basis/bin/shared_bash_function.sh @@ -235,6 +235,65 @@ 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" + export TF_VAR_public_subnet_ocid=$TF_VAR_subnet_ocid + export TF_VAR_private_subnet_ocid=$TF_VAR_subnet_ocid + fi + else + echo 'File env.sh does not contain: # export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx' + fi +} + create_deployment_in_apigw() { # Publish the API with an API Deployment to API Gateway if [ "$APIGW_DEPLOYMENT_OCID" != "" ]; then From 337ec0b451085a6250e7611a063eb4865e25309c Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 20 Nov 2023 18:23:07 +0100 Subject: [PATCH 3/6] v1.6 --- basis/bin/shared_bash_function.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/basis/bin/shared_bash_function.sh b/basis/bin/shared_bash_function.sh index 8815ace6..b0b0ece6 100755 --- a/basis/bin/shared_bash_function.sh +++ b/basis/bin/shared_bash_function.sh @@ -286,11 +286,10 @@ livelabs_green_button() { 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 - else - echo 'File env.sh does not contain: # export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx' fi } From a9c3a4db04cf2f2d1981da6ac6c5825c1e193639 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 20 Nov 2023 18:23:48 +0100 Subject: [PATCH 4/6] v1.6 --- basis/bin/livelabs_green_button.sh | 69 ------------------------------ 1 file changed, 69 deletions(-) delete mode 100755 basis/bin/livelabs_green_button.sh diff --git a/basis/bin/livelabs_green_button.sh b/basis/bin/livelabs_green_button.sh deleted file mode 100755 index 1928f94c..00000000 --- a/basis/bin/livelabs_green_button.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash -# -# For LiveLabs only, auto-fill automatically -# - TF_VAR_compartment_ocid, -# - TF_VAR_vcn_ocid -# - TF_VAR_public_subnet_ocid, TF_VAR_private_subnet_ocid -export BIN_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -export PROJECT_DIR=${BIN_DIR%/*} - -# Shared BASH Functions -. $BIN_DIR/shared_bash_function.sh - -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" - 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" - fi - else - echo 'File env.sh does not contain: # export TF_VAR_compartment_ocid=ocid1.compartment.xxxxx' - fi -} - -livelabs_green_button \ No newline at end of file From 2f6248b3562332da94ac8575ea0e862c2d72ae12 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 20 Nov 2023 18:24:44 +0100 Subject: [PATCH 5/6] v1.6 --- basis/bin/auto_env.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/basis/bin/auto_env.sh b/basis/bin/auto_env.sh index 3d518d4b..f2699323 100755 --- a/basis/bin/auto_env.sh +++ b/basis/bin/auto_env.sh @@ -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 From 4eb7c8be4d4fb85a02f886563cbd4eec69d46cf0 Mon Sep 17 00:00:00 2001 From: Marc Gueury Date: Mon, 20 Nov 2023 18:36:35 +0100 Subject: [PATCH 6/6] v1.6 --- basis/bin/shared_bash_function.sh | 6 ++++++ py_oci_starter.py | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/basis/bin/shared_bash_function.sh b/basis/bin/shared_bash_function.sh index b0b0ece6..eed8fb0f 100755 --- a/basis/bin/shared_bash_function.sh +++ b/basis/bin/shared_bash_function.sh @@ -290,6 +290,12 @@ livelabs_green_button() { 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 } diff --git a/py_oci_starter.py b/py_oci_starter.py index 09fd575f..cdc686f7 100755 --- a/py_oci_starter.py +++ b/py_oci_starter.py @@ -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')