3

We're deploying our software on behalf (OAuth2) of users on Google Cloud. We've managed to automate most of it, but there's one bit that's missing.

  1. Creating the project is done with https://godoc.org/google.golang.org/api/cloudresourcemanager/v1#ProjectsService.Create
  2. Enabling the required APIs (compute, storage, etc) is done with google.golang.org/api/servicemanagement/v1#ServicesService.Enable (can't post as full link thanks to the very bright SO limitations)
  3. Creating the instance is done with google.golang.org/api/compute/v1#InstancesService.Insert

The missing bit is between step 1 and step 2: in order to make use of the Service Management API to enable the needed APIs, we need the Service Management API itself to be enabled on the project (how ironic). I'm hoping there must be a way to create a project with some APIs enabled from the start, maybe with cloudresourcemanager, or maybe with https://godoc.org/google.golang.org/api/deploymentmanager/v2, but I haven't found it so far.

So, to restate: does anyone know if it's possible (in Go) to create a Google Cloud project with some specific Google Cloud APIs enabled right on/after creation?

mpl
  • 33
  • 5

2 Answers2

0

The Google Cloud Resource Manager API is very limited in what it will allow you to do.

while it does have a projects.update method it does not support enabling APIs. Your going to have to manually edit the project.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
0

Use the Service Usage API: https://cloud.google.com/service-usage/docs/reference/rest/

(updated)

Rob Kochman
  • 323
  • 2
  • 4
  • Yes thanks, I eventually noticed, that as opposed to what the doc says, I didn't need to explicitly enable the API to use is (see end of commit message at https://camlistore-review.googlesource.com/c/9906/4). Hmmo, are you saying that I should not expect servicemanagement to keep on working by default, and that I should use serviceuser instead? – mpl Apr 19 '17 at 19:18
  • serviceuser is intended to be the service consumer-facing API. It's useful in that you can enable/disable services without having to enable the servicemanagement API. – Rob Kochman Apr 19 '17 at 21:26
  • This is not working for me. First of all, the "name" parameter to the Enable method is not described in the docs. In the source json one can find "A valid path would be:\n- /v1/projects/my-project/services/servicemanagement.googleapis.com:enable" but one has to pass something like "projects/my-project/services/servicemanagement.googleapis.com". But when I try to enable the servicemanagement API I get the response: googleapi: Error 403: Google Service User API has not been used in project xxxx before or it is disabled. – TvE Aug 30 '17 at 23:31
  • I tried the gcloud cli tool and it handles the enablement fine. Looking at the HTTP it produces and instead of a URL like /v1/project//services/:enable it uses just /v1/services/:enable and passes the project ID in the body as "consumerId" field. I tricked the ProjectsServicesService.Enable method to do that by passing the consumerId stuff to the Do() method. Looks like the library needs some fixes... – TvE Aug 30 '17 at 23:39
  • @TvE Yo tve, im getting the same Error 403: Google Service User API has not been used in project. Im doing this in python though. did you ever solve this? –  Sep 03 '19 at 19:54
  • Try using the Service Usage API: https://cloud.google.com/service-usage/docs/reference/rest/ – Rob Kochman Sep 04 '19 at 21:12
  • @TvE I can, but that would require me to enable the api. That's why I've been trying to use the Service User API, which is "enabled by default", but I'm getting the same thing as you. I'm trying to automate this process and enabling manually the api on each project is not very efficient... any other tips? –  Sep 06 '19 at 00:18
  • I updated the answer. You want "Service Usage" not "Service User" – Rob Kochman Sep 09 '19 at 04:04