How to check which gcloud project is active

Viewed 7215

To see all your gcloud projects you use command gcloud projects list. To switch to a specific project, you use gcloud config set project PROJECT_ID.

But what command can you use when you want to check which project is active? By which I mean, on which project was called the set command last?

1 Answers
gcloud config get-value project

You can always type gcloud config --help

There's a very cool and well-hidden interactive tool: gcloud beta interactive that will help with gcloud command completion.

Personally, I recommend not using configurations to hold default values (for e.g. project) in order to (help) avoid "To which project did I just apply that command?" issues.

IMO, it's much better to be more explicit and I prefer:

gcloud ... --project=${PROJECT}

If, like me, you put the project value in a variable, you can still make mistakes but it is easier to avoid them.

You can also define sets of configurations and then use gcloud ... --configuration=${CONFIG} and this works too as long as you don't set values in the default config

Related