Search code examples
google-cloud-platformgoogle-apicloudcommand-line-interfacegoogle-cloud-console

Enabling all API in Google Cloud project


Google Cloud needs enabled API before many things are possible to be done.

Enabling needs just one CLI command, and usually is very fast. Enabling is even proposed by CLI if I try to do something which requires not-enabled API. But it anyway interrupts development.

My question is why they are not enabled by default? And is it ok if I enable them all just after creating new project to don't bother about enabling them later?

I would like to understand purpose of such design and learn best practices.


Solution

  • Enabling services enables access to (often billed) resources.

    It's considered good practice to keep this "surface" of resources constrained to those that you(r customers) need; the more services you enable, the greater your potential attack surface and potential bills.

    Google provides an increasing number of services (accessible through APIs). It is highly unlikely that you would ever want to access them all.

    APIs are enabled by Project. The Project creation phase (including enabling services) is generally only a very small slice of the entire lifetime of a Project; even of those Projects created-and-torn-down on demand.

    It's possible to enable the APIs asynchronously, permitting you to enable-not-block each service:

    for SERVICE in "containerregistry" "container" "cloudbuild" ...
    do
      gcloud services enable ${SERVICE}.googleapis.com --project=${PROJECT} --async
    done
    

    Following on from this, it is good practice to automate your organization's project provisioning (scripts, Terraform, Deployment Manager etc.). This provides a baseline template for how your projects are created, which services are enabled, default permissions etc. Then your developers simply fire-and-forget a provisioner (hopefully also checked-in to your source control), drink a coffee and wait these steps are done for them.