Skip to content

Commit

Permalink
zone edit
Browse files Browse the repository at this point in the history
  • Loading branch information
themobileprof committed Nov 28, 2023
1 parent a085d89 commit e2542ee
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 61 deletions.
9 changes: 5 additions & 4 deletions gcloud_config
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ zone_setup(){

gcloud compute project-info add-metadata --metadata google-compute-default-region=$regionValue,google-compute-default-zone=$zoneValue

# Initialize Gcloud
echo "We recommend that you setup a default zone as part of the setup below"
gcloud init

fi
}

# Initialize Gcloud
gcloud init
}
62 changes: 5 additions & 57 deletions gcloud_vm
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ main(){

# Check if there is a default zone, if not, Google init
zone=$(gcloud config get-value compute/zone)
if [ -z "$zone" ]
then
while [ -z "$zone" ]
do
# Initialize Google Cloud
echo "We cannot detect a Zone in your configuration, so let us help you with configuration. Please remember to configure your zone as us-west, us-central, or us-east especially if you need the Google free VM"
read -p "Press <Enter> to proceed..."
gcloud init
fi

# Ensure User Sets Zone
zone_setup
zone=$(gcloud config get-value compute/zone)
done


# Name your machine with a unique name
echo ""
Expand All @@ -62,58 +62,6 @@ main(){
fi
}

zone_setup(){
############################################################
## DO NOT ASSUME THE ZONES AND REGIONS - GET IT FROM GCLOUD
############################################################
local zone=$(gcloud config get-value compute/zone)
if [ -z "$zone" ]
then
echo "We cannot detect a Zone in your configuration"
echo "What Region do you want to set your resources to?"
echo "1. US-West"
echo "2. US-Central"
echo "3. US-East"

while [ -z "$zoneNum" ]
do
read -p "Please select (1, 2, or 3): " zoneNum
if [[ -n ${zoneNum//[0-9]/} ]]; then
unset zoneNum
fi
done

local letters=(a b c)
local a=$((RANDOM%3+1))
local b=$((RANDOM%3))


if [ "${zoneNum,,}" = "2" ]; then
zoneValue="us-central${a}-${letters[$b]}"
regionValue="us-central${a}"
elif [ "${zoneNum,,}" = "3" ]; then
zoneValue="us-east${a}-${letters[$b]}"
regionValue="us-east${a}"
else
zoneValue="us-west${a}-${letters[$b]}"
regionValue="us-west${a}"
fi

echo "You are about to set your Zone to $zoneValue, press <Enter> to continue"
read

gcloud compute project-info add-metadata --metadata google-compute-default-region=$regionValue,google-compute-default-zone=$zoneValue


else # If there is a zone configuration, set it as a metadata
gcloud compute project-info add-metadata --metadata google-compute-default-zone=$zone
fi

# Initialize Gcloud
gcloud init
}


free_vm(){

# Get a US Zone except us-south
Expand Down

0 comments on commit e2542ee

Please sign in to comment.