问题
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:
- Select configuration (one of the following)
gcloud config configurations create my_configuration
gcloud config configurations activate my_configuration
- Set up credentials (one of the following)
- (Interactive)
gcloud auth login
gcloud config set account my_existing_credentials
gcloud auth activate-service-account
- (Interactive)
- Set project
gcloud config set project my_project
- List of accessible projects for set credentials can be seen via
gcloud projects list
- List of accessible projects for set credentials can be seen via
- (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
- List of zones can be obtained via
- (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
- List of regions can be obtained via
- (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