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?
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.
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.
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:
gcloud config configurations create my_configuration
gcloud config configurations activate my_configuration
gcloud auth login
gcloud config set account my_existing_credentials
gcloud auth activate-service-account
gcloud config set project my_project
gcloud projects list
gcloud config set compute/zone my_default_gce_zone
gcloud compute zones list
gcloud config set compute/region my_default_gce_region
gcloud compute regions list
gsutil config -n -o ~/.boto
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With