When running a Terraform Apply, I get the following:
google_cloudbuild_trigger.build-trigger: Creating...
╷
│ Error: Error creating Trigger: googleapi: Error 400: Repository mapping does not exist. Please visit https://console.cloud.google.com/cloud-build/triggers/connect?project=<blah> to connect a repository to your project
The terraform plan does reveal that the repository is named correctly, but the issue is that you have to open the Cloud Build UI and “connect the repository” between GitHub and Cloud Build before the Terraform call can succeed.
While this works for deploying existing applications to different places, this somewhat defeats the purpose for being able to seamlessly deploy new/arbitrary github apps, and we have to tell developers to log into cloud build and link the repo first.
any updates/success on this? just ran also into it and I’m wondering what a proper solution could be …
on SO there is the suggestion to somehow have a persisten project which is connected but that’s kind of sad
I ran into a similar problem. In my case, the repository mapping was configured only on a specific region (us-central1), but the Terraform requested to create a build trigger onto the global resion, resulting in “repository mapping does not exist” error.
Since there is no region parameter in the google_cloudbuild_trigger resource, I turned my repository mapping into global for a quick workaround. But I also guess the resource should support explicit region parameter too.
If you dont care about the fancy github-gcloud integration features and just want IaC all-the-way you can combine webhook-trigger and build template with custom steps to achieve what you want.
Adding another update for anyone that comes across this. I could not use “2nd Gen” repository connections when creating a trigger. I found only “1st Gen” repository connections that were manually created in the console could be referenced.
That being said, you can use a region (and not global) with this 1st Gen repo connection. Here is what worked for me:
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "5.5.0"
}
}
}
provider "google" {
project = var.project_id
}
resource "google_cloudbuild_trigger" "dev-trigger" {
project = var.project_id
location = "northamerica-northeast2"
name = "dev-trigger"
filename = "cloudbuild.yaml"
tags = ["dev"]
github {
owner = "owner"
name = "repo_name" # repo name only - does not include project/owner in front with a slash
push {
branch = "^dev$"
}
}
substitutions = {
_FOO = "BAR"
}
}