Skip to content
Advertisement

GCP API Client Libraries Java Examples – com.google.api.services.deploymentmanager.DeploymentManager

I am looking to automate the provisioning of google cloud resources using Deployment Manager. Only I want to use the JAVA API library instead of gcloud.

Specifically need to provision the following components using DeploymentManager.

  1. Cloud SQL – MSSQL
  2. Cloud Run Service
  3. VPC Network with the Connector to be used to connect Cloud Run to the Cloud SQL.

I think com.google.api.services.deploymentmanager.DeploymentManager is the starting point but I am not very sure.

This is what I have so far

JavaScript

I get the following error in the last line:

JavaScript

I do have the environment variable GOOGLE_APPLICATION_CREDENTIALS pointing to a file that contains the service account key (generated using gcloud auth application-default login command)

Any insights would be very helpful.

Advertisement

Answer

Okay, it looks like I have got it working with the code below.

I have demonstrated how to use gcloud command using processbuilder as well as the DeploymentManager API. I had to use GoogleCredentials to read the service-account-key-file and pass that to the HttpCredentialsAdapter.

It was very hard to locate but this guide came in handy. Posting a link as reference for someone who stumbles by later.

Let me know if this can be done in a better way.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement