Can I automate Google Cloud SDK gcloud init - interactive command

跟風遠走 提交于 2019-12-29 02:57:24

问题


Documentation on Google Cloud SDK https://cloud.google.com/sdk/docs/ directs one to run gcloud init after installing it.

Is there a way to automate this step given that gcloud init is an interactive command?


回答1:


One does not need to run gcloud init. Main goal is to make sure credentials are configured and perhaps the project property is set. If you have service-account credentials, gcloud can be configured and ready to go via the following:

gcloud auth activate-service-account --key-file=credential_key.json
gcloud config set project my-project

For completeness gcloud init essentially runs the following steps:

  1. Select configuration (one of the following)
    • gcloud config configurations create my_configuration
    • gcloud config configurations activate my_configuration
  2. Set up credentials (one of the following)
    • (Interactive) gcloud auth login
    • gcloud config set account my_existing_credentials
    • gcloud auth activate-service-account
  3. Set project
    • gcloud config set project my_project
      • List of accessible projects for set credentials can be seen via gcloud projects list
  4. (Optional) Set default GCE zone (Compute API must be enabled)
    • gcloud config set compute/zone my_default_gce_zone
      • List of zones can be obtained via gcloud compute zones list
  5. (Optional) Set default GCE region (Compute API must be enabled)
    • gcloud config set compute/region my_default_gce_region
      • List of regions can be obtained via gcloud compute regions list
  6. (Optional) Create default config file for gsutil
    • gsutil config -n -o ~/.boto


来源:https://stackoverflow.com/questions/42379685/can-i-automate-google-cloud-sdk-gcloud-init-interactive-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!