Can't deploy Cloud build trigger based on Pub/Sub event : Error 400: Request contains an invalid argument

Hello,

In my GCP project I have 2 repos on artifact registry (Initial and Final). My need is the following: when an image is updated on the Initial repo, I want it to be automatically copied to the Final repo.
To do this, I’d like to set up a Pub/Sub topic that listens on the Initial repo, and a Cloud Build Trigger that is triggered by Pub/Sub as soon as it receives a message.

I build my resources with terraform. According to the official documentation (https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloudbuild_trigger.ht…), as my trigger is triggered by a Pub/Sub event, i can’t use the filename attribute to specify where my cloud build file is. i have to use the git_file_source attribute.

so I created the following resources with terraform :

  • a pub/sub topic

  • a cloud source repository

  • a cloud build trigger

like this :

resource "google_project_service" "source_repositories_api" {
  project = "my_project_id"
  service = "sourcerepo.googleapis.com"
}

resource "google_sourcerepo_repository" "my_repo" {
  depends_on = [ google_project_service.source_repositories_api ]
  project = "my_project_id"
  name    = "mi-repo"
}

resource "google_pubsub_topic" "image_updates_topic" {
  name    = "image-updates"
  project = "my_project_id"
}

resource "google_cloudbuild_trigger" "trigger_pubsub" {
  name     = "tri-pubsub"
  location = "europe-west1"

  pubsub_config {
    topic = google_pubsub_topic.image_updates_topic.id
  }

  approval_config {
    approval_required = false
  }

  git_file_source {
    path      = "cloudbuild.yaml"
    repository = google_sourcerepo_repository.my_repo.id
    revision  = "refs/heads/master"
    repo_type = "CLOUD_SOURCE_REPOSITORIES"
  }
}

Having first uploaded the cloudbuild.yaml file to the repo

As I want to test the simple creation of my trigger, the cloudbuild.yaml file is very simple:

steps:
  - name: ubuntu
    args:
      - echo
      - hello world
options:
  logging: CLOUD_LOGGING_ONLY

However, I get the following error:

╷
│ Error: Error creating Trigger: googleapi: Error 400: Request contains an invalid argument.
│ 
│   with google_cloudbuild_trigger.trigger_pubsub,
│   on cloud_build.tf line 17, in resource "google_cloudbuild_trigger" "trigger_pubsub":
│   17: resource "google_cloudbuild_trigger" "trigger_pubsub" {
│ 
╵

maybe I need to use a new attribute like source_to_build, but I don’t see the point here.

Can you please help me?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.