Reputation: 1802
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?
Upvotes: 46
Views: 81061
Reputation: 1237
You can use gcloud projects list --filter='lifecycleState:ACTIVE'
to get all active projects.
Or you can list them all showing lifecyclestate
and filter with grep or other bash stuff:
$ gcloud projects list --format="table(projectNumber,projectId,createTime.date(tz=LOCAL),lifecycleState)" --limit 10
PROJECT_NUMBER PROJECT_ID CREATE_TIME LIFECYCLE_STATE
310270846648 again-testing-no-notebook 2022-12-11T07:03:03 ACTIVE
[...]
Hope this helps.
Upvotes: 1
Reputation: 40091
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
Upvotes: 78