Creating Cloud Build Trigger from Terraform

I am trying to create a Cloud Build trigger from Terraform but I am getting "Blocks of type "github" are not expected here." error.

My code:

terraform {
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "3.5.0"
    }
  }
}

provider "google" {
  credentials = file("key-file.json")

  project = var.project_id
}

resource "google_cloudbuild_trigger" "github-trigger" {
  name = "github-trigger"
  filename = "cloudbuild.yaml"
  location = "europe-west1"
  github {
    owner = <owner>
    name = <name>
    push {
      branch = <branch>
    }
  }
    
} 

When I am not including github block and location, the code is working and the trigger is being created.

My encoding is UTF-8 and I am running the code in VS Code.

Any idea why I am getting this error?

1 Answer

Since you are using provider version that is three years old, it will not work that way. You can either update to a newer version that supports github argument or make sure you are using the correct syntax for the provider version you have. My guess is that the closest to what you want is using trigger_template block [1] where you can define similar arguments:

  • project_id
  • repo_name
  • dir
  • branch_name
  • tag_name
  • commit_sha

However, I strongly suggest updating to a newer provider version.


[1]

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest