我可以自动化 Google Cloud SDK gcloud init - 交互式命令吗

Can I automate Google Cloud SDK gcloud init - interactive command

关于 Google Cloud SDK https://cloud.google.com/sdk/docs/ 的文档在安装后将其指向 运行 gcloud init

考虑到 gcloud init 是一个交互式命令,有没有办法自动执行此步骤?

不需要运行gcloud init。主要目标是确保配置凭据并且可能设置项目 属性。如果您有服务帐户凭据,则可以通过以下方式配置 gcloud 并准备就绪:

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

为了完整性 gcloud init 本质上 运行 以下步骤:

  1. Select配置(以下之一)
    • gcloud config configurations create my_configuration
    • gcloud config configurations activate my_configuration
  2. 设置凭据(以下之一)
    • (互动)gcloud auth login
    • gcloud config set account my_existing_credentials
    • gcloud auth activate-service-account
  3. 设置项目
    • gcloud config set project my_project
      • 可以通过以下方式查看设置凭据的可访问项目列表 gcloud projects list
  4. (可选)设置默认 GCE 区域(必须启用计算 API)
    • gcloud config set compute/zone my_default_gce_zone
      • 区域列表可以通过gcloud compute zones list
      • 获得
  5. (可选)设置默认 GCE 区域(必须启用计算 API)
    • gcloud config set compute/region my_default_gce_region
      • 区域列表可以通过gcloud compute regions list
      • 获取
  6. (可选)为 gsutil 创建默认配置文件
    • gsutil config -n -o ~/.boto