8

I'm working on a Terraform project that will set up all the GCP resources needed for a large project spanning multiple GitHub repos. My goal is to be able to recreate the cloud infrastructure from scratch completely with Terraform.

The issue I'm running into is in order to setup build triggers with Terraform within GCP, the GitHub repo that is setting off the trigger first needs to be connected. Currently, I've only been able to do that manually via the Google Cloud Build dashboard. I'm not sure if this is possible via Terraform or with a script but I'm looking for any solution I can automate this with. Once the projects are connected updating everything with Terraform is working fine.

TLDR; How can I programmatically connect a GitHub project with a GCP project instead of using the dashboard?

iicaptain
  • 1,065
  • 1
  • 13
  • 37
  • Which is the GCP resource you want to use? – Marko E Nov 04 '21 at 08:48
  • Google Cloud Build to build from a GitHub repo for Cloud Run. – iicaptain Nov 04 '21 at 15:19
  • Does this help https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloudbuild_trigger#nested_github? – Marko E Nov 04 '21 at 15:42
  • Thanks for trying but no, I’m already using that already. The issue is if the repo isn’t already connected that results in a 400 error because it needs to have to repo connected before adding triggers. If I manually connect the repo in Google’s dashboard it works but I want to do that step programmatically. – iicaptain Nov 04 '21 at 19:10
  • https://github.com/GoogleCloudPlatform/terraformer Does this help? – Divyani Yadav Nov 06 '21 at 15:55

1 Answers1

2

Currently there is no way to programmatically connect a GitHub repo to a Google Cloud Project. This must be done manually via Google Cloud.

My workaround is to manually connect an "admin" project, build containers and save them to that project's artifact registry, and then deploy the containers from the registry in the programmatically generated project.

iicaptain
  • 1,065
  • 1
  • 13
  • 37