Sudipta Deb

Sudipta Deb

Founder of Technical Potpourri, Co-Founder of Shrey Tech, Enterprise Cloud Architect

In the ever-evolving landscape of cloud computing, Google Cloud Platform (GCP) stands out as a beacon of innovation and efficiency. Among its suite of robust tools, one particularly shines for its versatility and user-friendliness: the Google Cloud Shell. This dynamic feature serves as a gateway to managing and manipulating cloud resources with ease and precision.

Google Cloud Shell is essentially a browser-based command line interface that offers a consistent development environment in GCP. It eliminates the need for local installations and configurations, providing a ready-to-use development environment with access to a wide array of Google Cloud resources.

While working with glcoud command, we need to specify values like RegionZone, or Project Id. Now entering these values with each commands is not a good experience. It also increases the chance of making typing errors.

So in this blog post, I am going to show you how you can set the common values in environment variables and use them instead of typing the actual values.

Get List of Available Regions

You can execute the below command in cloud console to get list of available regions.

gcloud compute regions list

From the list, select the region and copy the name.

Create Environment Variable for Region

Step 1

Create the environment variable and include the region you selected in the previous step. In the below command, I am using the region us-east1.

INFRACLASS_REGION=us-east1

Step 2

Validate the environment variable using echo command.

echo $INFRACLASS_REGION

Append the Environment Variable to a File

Step 1

Create subdirectory and a config file.

mkdir myenv

touch myenv/config

Step 2

Append the value of your Region environment variable to the config file.

echo INFRACLASS_REGION=$INFRACLASS_REGION >> ~/myenv/config

Create Environment Variable for Project Id

Step 1

Create the environment variable and include the Project Id.

INFRACLASS_PROJECT_ID=[YOUR PROJECT ID]

Step 2

Validate the environment variable using echo command.

echo $INFRACLASS_PROJECT_ID

Append the Environment Variable to a File

Step 1

Append the value of your Project Id environment variable to the config file.

echo INFRACLASS_PROJECT_ID=$INFRACLASS_PROJECT_ID >> ~/myenv/config

Set the Environment Variables

Finally use the source comand to set the environment variables and use the echo command to verify that the project variable was set:

source myenv/config

echo $INFRACLASS_PROJECT_ID

Modify the bash Profile & Create Persistence

Execute the belo command

nano .profile

Then add the line at the end of the file and save:

source myenv/config

Now if you close your could shell and open a new one (resetting the vm), you can execute the command and get the desired output

echo $INFRACLASS_PROJECT_ID

Final Thoughts

In conclusion, Google Cloud Shell is more than just a command-line interface; it’s a comprehensive, secure, and efficient environment for managing your cloud resources. Its ease of use, coupled with robust features, makes it an indispensable tool for anyone working in the Google Cloud ecosystem.

Disclaimer

This article is not endorsed by Salesforce, Google, or any other company in any way. I shared my knowledge on this topic in this blog post. Please always refer to Official Documentation for the latest information.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *