Open In App

How To Change The Project In GCP Using CLI Commands ?

Last Updated : 05 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Google Cloud Platform(GCP) offers various Cloud services such as cloud storage, cloud computing, deploying and scaling applications in the cloud e,c. GCP offers pay-per-use services. Apart from these, GCP offers many other services like hosting your websites in the cloud, running your own Operation System from the Cloud, and other cloud computing processes.

Projects In Google Cloud Platform ( GCP )

In GCP, projects are basic units that act as containers to organize the work, resources, billings, etc. Each project has its resources, access controls, billings, etc. The cost for resources is calculated and billed separately for each project. You need to set up a project first to work with any cloud service offered by GCP. Each GCP project contains a unique PROJECT_ID and a PROJECT_NUMBER. While the PROJECT_ID is user-defined, the PROJECT_NUMBER is assigned by GCP.

GCP Console Vs CLI

GCP offers both CONSOLE and a Command Line Interface (CLI). The Console is the Graphical User Interface (GUI) to interact with the platform. You can use the Console to create a project, change the project, launch a VM etc. On the other hand, CLI is the command line tool to interact with the platform. You can use commands to create or change the project and all other tasks.

Steps To Change The Project In GCP Using CLI Commands

Step 1: Goto GCP Cloud Console

Step 2: Create a Project

Step 3: Activate Cloud Shell from the GCP Console.

  • Cloud Shell is the Command Line tool provided by GCP.
  • Click on the top right button as shown below to activate Cloud Shell. We need to activate the Cloud Shell to interact with GCP using CLI commands.

Activating cloud shell

Step4: List all the projects

  • Once the Cloud Shell is activated, list all the projects using the below command:
gcloud projects list
  • The above command will list all the projects in your GCP account as shown below.
  • You can see the PROJECT_ID, NAME and PROJECT_NUMBER for all the projects. Kindly note the PROJECT_ID of the project to which you need to change.

List the Projects

  • The above image shows that I have three projects in my GCP account. They are

1. My First Project
2. GeeksforGeeks Project and
3. geekyWebsite

  • In the remaining section, I will walk you through how to change the project from Website for geek to GeeksforGeeks Project.
  • Kindly note the PROJECT_ID of GeeksforGeeks Project is geeksforgeeks-project1.

Step 5: Check the currently configured Project

Before changing the project, check the currently configured project using the below command

gcloud config list project

The above commands give the PROJECT_ID of the currently configured project as project = PROJECT_ID. The below image shows that I am in the project named “Website for geek” with PROJECT_ID as geekywebsite.

Currently configured Project

Step 6: Change the project using the below command

gcloud config set project PROJECT_ID
  • For example, if I want to change the project from Website for geek to GeeksforGeeks Project I will use the below command
gcloud config set project geeksforgeeks-project1
  • geeksforgeeks-project1 is the PROJECT_ID of GeeksforGeeks Project. You can check the ID from the previous all projects list image.

Step 7: Confirm the change

  • This can be done by checking the currently configured project in our previous command
gcloud config list project
  • As you can see the PROJECT_ID is now changed to geeksforgeeks-project1 from the below image.

confirm changing Project

Congratulations! You have successfully changed the project using CLI commands.

Changing Projects In GCP Using CLI – FAQs

What Is A GCP Project?

In GCP, projects act as containers to organize the work, resources, billings etc. Each project has its own resources, access controls, billings etc.

What Is GCP CLI?

CLI is the command line tool to interact with the GCP platform. You can use commands to create or change the project and all other tasks.

Do I Need To Enable Billing For Creating A Project?

A project by default don’t need a billing account. But if your project uses any resource that needs billing, then you need to enable billing.

What Is The Cost Of Creating A Project?

You can create upto 12 projects for free in GCP. However, number may vary with time. Please confirm with your cloud service provider.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads