Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I automate Google Cloud SDK gcloud init - interactive command

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?

like image 862
cherba Avatar asked Feb 21 '17 23:02

cherba


People also ask

Which Google Cloud interface allows for scripting actions in a set of command line?

What is the gcloud CLI? The Google Cloud CLI is a set of tools to create and manage Google Cloud resources. You can use these tools to perform many common platform tasks from the command line or through scripts and other automation.

Can I run gcloud command on cloud function?

So, bottom-line you can't issue gcloud commands from a Google Cloud Function. To interact with other Google Cloud Platform Services, you have their respective client libraries in many languages, Python being one of them.


1 Answers

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
like image 188
cherba Avatar answered Sep 26 '22 01:09

cherba