Google Cloud Platform (GCP) has a lot to offer, one huge offering is their command-line software development kit (CLI SDK). This SDK contains tools that help differentiate GCP from other cloud providers and helps improve the developer experience and efficiency. In this blog post, I will dive into the very basics of gcloud
and how to get it set up. In future articles, I will cover actual gcloud
, bq
, and gsutil
commands that will perform actions in GCP.
Let’s learn together!
Introduction
GCP gives users the ability to perform all UI actions through the command-line, and even provides additional actions that can’t be done in the GCP UI. The gcloud
CLI tool is a crucial tool for almost all GCP Cloud Engineers. It can be used to automate tasks, quickly perform tasks, perform tasks that you can’t perform in the UI, and much more. The gcloud
CLI tool is significant in size, and I am excited to cover how to install and initialize it in this blogpost. This blogpost is going to be an ongoing series covering the GCP CLI SDK. The only prerequisite for this article if you are following along, is to have access to a GCP Project. Additionally, this article is written assuming that you have basic Terminal knowledge and Google Cloud services knowledge.
Let’s dive in!
Installation and Setting Up
I will talk about how to install and authenticate the GCP SDK CLI on your local computer. To install you will need to follow Google Cloud’s steps located here, which differ depending on your Operating System.
Once installed, you will need to initialize the CLI tool. To do this, you will need to run gcloud init
. This will give you the option to initialize a new configuration. Follow the prompts and name it something like “Development”, “Staging”, or “Production”, which will correspond to the GCP project’s environment. To learn more about initialization, read more here.
Configurations
Configurations are an integral part of gcloud
, especially if you have different projects within GCP. For example, you could have “Development”, “Staging”, and “Production” configurations, where each one houses the proper gcloud
settings for each respective environment.
To create a configuration, you simply reuse the command you just used, gcloud init
and select the prompt for Creating a New Configuration
.
In order to switch between configurations, you will need to run the following command: gcloud config configurations activate <configuration-name>
.
You can check which config is currently active with the following command: gcloud config list
. This will print out the config details.
In summary, Configurations are used to separate service locations, project IDs, project numbers, project names, etc… all of the project-level variables. They are super useful when you are working on multiple projects within GCP.
Modifying Existing Configurations
Modifying existing configurations is very simple within gcloud
. All you need to do is run the following command after you have activated the configuration you’d like to modify: gcloud config set <property> <value>
.
For example, if you would like set the zone for your future compute engine instance deployments from gcloud
, you would run the following command:gcloud config set compute/zone us-central1-b
, where us-central1-b
zone is being set.
A list of all properties that are available to set is located here towards the middle of the page in the “Available Properties” section.
Unset and Get
You are also able to print out specific property values to the terminal and can unset
, or delete values from a property.
To print out specific property values to the terminal, you would run gcloud config get <property>
.
An example would be: gcloud config get compute/zone
. This would print out the current, active configuration’s compute/zone property value.
Sometimes you want to simply delete and clear a value from a property. The following command will do that: gcloud config unset <property>
.
Conclusion
This blogpost was meant to give you a basic workable setup for the GCP CLI SDK. In this blogpost, you learned how to install the SDK, initialize it, add new configurations, modify existing configurations, and a few simple uses of gcloud
.
I hope that this article helped you get started with GCP CLI SDK and I am excited to write future articles on how to use the powerful SDK.
Thank you for reading. Happy Coding!