How to change the project in GCP using CLI commands

前端 未结 16 1984
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 18:07

How can i change the current running project to another project in GCP (Google Cloud Platform) account using cli commands other than using

16条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-29 18:55

    I do prefer aliases, and for things that might need multiple commands, based on your project needs, I prefer functions...

    Example

    function switchGCPProject() {
            gcloud config set project [Project Name]
            // if you are using GKE use the following
            gcloud config set container/cluster [Cluster Name]
            // if you are using GCE use the following
            gcloud config set compute/zone [Zone]
            gcloud config set compute/region [region]
            // if you are using GKE use the following
            gcloud container clusters get-credentials [cluster name] --zone [Zone] --project [project name]
            export GOOGLE_APPLICATION_CREDENTIALS=path-to-credentials.json
    }
    

提交回复
热议问题