Skip to content

Instantly share code, notes, and snippets.

@ajanderson1
Last active August 23, 2023 08:09
Show Gist options
  • Save ajanderson1/d62498ce5aa42c2d5b4808b83dc1482e to your computer and use it in GitHub Desktop.
Save ajanderson1/d62498ce5aa42c2d5b4808b83dc1482e to your computer and use it in GitHub Desktop.
GCP Configurations

Working with GCP Configuations

A collection of scripts and tools to help with GCP configurations.

#!/bin/bash
# Check if tput command is available
if command -v tput > /dev/null && [ -f "formatting_aliases.sh" ]; then
source formatting_aliases.sh
else
echo -e "Warning: Formatting aliases are not set (please set in 'formatting_aliases.sh') or 'tput' is unavailable. Continuing without formatting."
fi
# List all available GCP configurations and save them to a temporary file
gcloud config configurations list > temp_configurations.txt
# Print the header separately
header=$(sed -n '1p' temp_configurations.txt)
echo "Available GCP configurations:"
echo " $header"
# Print the configurations starting from line 2, excluding the header
index=1
sed '1d' temp_configurations.txt | while read line; do
echo "$index: $line"
index=$((index + 1))
done
# Prompt the user to select one to activate
read -p "Enter the row number of the configuration you want to activate: " row_number
# Extract the selected configuration name (increment row number by 1 to account for the header)
selected_configuration=$(sed -n "$((row_number + 1))p" temp_configurations.txt | awk '{print $1}')
# Echo the CLI command that will be executed
echo -e "Run the following command to activate:\n${yellow}gcloud config configurations activate $selected_configuration${reset}"
# Execute the command to activate the selected configuration
gcloud config configurations activate $selected_configuration
# Remove the temporary file
rm temp_configurations.txt
echo "Configuration $selected_configuration has been\nactivated."
# This file contains all the formatting variables for the scripts in this repo.
# USAGE:
# source ~/Scritps/formatting.sh
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
magenta=$(tput setaf 5)
cyan=$(tput setaf 6)
white=$(tput setaf 7)
black=$(tput setaf 8)
bold=$(tput bold)
dim=$(tput dim)
underline=$(tput smul)
no_underline=$(tput rmul)
reverse=$(tput rev)
standout=$(tput smso)
no_standout=$(tput rmso)
reset=$(tput sgr0)
bold=$(tput bold)
reset='\033[0m' # No Color
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment