Cloud build manual trigger for source in bucket as .tar.gz

please help me to find code snippet to create a GCP cloudbuild triger , where the source code is in GCS bucket and inline build steps. I was able to do this in GCP console, but unable todo in terraform to find right combination . please help .

resource “google_cloudbuild_trigger” “build-trigger-manual” {
name = “my-inline-manual”
location = “us-central1”

approval_config {
approval_required = false
}

trigger_template {

storage_source {

source = “gs://us-central1-test-bucket/cloudbuild.tar.gz”

}

build {

     step {
  name = "gcr.io/cloud-builders/gcloud"
  args = ["auth", "configure-docker"]
}

step {
  name = "gcr.io/cloud-builders/gsutil"
  args = ["cp", "gs://us-central1-test-bucket/cloudbuild.tar.gz", "/workspace/"]
}
step {
  name = "gcr.io/cloud-builders/docker"
  args = ["run","--rm", "-v", "/workspace:/workspace", "busybox","tar", "-xzf","/workspace/cloudbuild.tar.gz","-C","/workspace/"]
}

 step {
  name = "gcr.io/cloud-builders/docker"
  args = ["build", "-t", "us-central1-docker.pkg.dev/myproject/gcf-artifacts/myflex:latest", "."]
}
step {
  name = "gcr.io/cloud-builders/docker"
  args = ["push", "us-central1-docker.pkg.dev/myproject/gcf-artifacts/myflex:latest"]
  
}

options {
  logging = "CLOUD_LOGGING_ONLY"
  dynamic_substitutions = true
}

source {
  storage_source {
    bucket = "us-central1-test-bucket"
    object = "cloudbuild.tar.gz"
  }
}

}
}

To create a Cloud Build trigger in Terraform for a source in a GCS bucket with inline build steps, you’ll adjust your Terraform configuration to directly specify the GCS source and build steps. Ensure the source block points to your GCS bucket and object, and define each build step within the build block. Omit the trigger_template for manual triggers, and use an empty string for filename to indicate inline steps. Replace placeholders with your actual project details.

resource “google_cloudbuild_trigger” “build_trigger_manual” {
name = “my-inline-manual”
location = “us-central1”

description = “Manually triggered build with source in GCS bucket”

filename = “” # Ensures inline build configuration is used

included_files = [
“gs://us-central1-test-bucket/cloudbuild.tar.gz”
]

source {
storage_source {
bucket = “us-central1-test-bucket”
object = “cloudbuild.tar.gz”
}
}

build {
step {
name = “gcr.io/cloud-builders/gcloud
args = [“auth”, “configure-docker”]
}

step {
  name = "gcr.io/cloud-builders/gsutil"
  args = ["cp", "gs://us-central1-test-bucket/cloudbuild.tar.gz", "/workspace/"]
}

step {
  name = "gcr.io/cloud-builders/docker"
  args = ["run", "--rm", "-v", "/workspace:/workspace", "busybox", "tar", "-xzf", "/workspace/cloudbuild.tar.gz", "-C", "/workspace/"]
}

step {
  name = "gcr.io/cloud-builders/docker"
  args = ["build", "-t", "us-central1-docker.pkg.dev/myproject/gcf-artifacts/myflex:latest", "."]
}

step {
  name = "gcr.io/cloud-builders/docker"
  args = ["push", "us-central1-docker.pkg.dev/myproject/gcf-artifacts/myflex:latest"]
}

options {
  logging = "CLOUD_LOGGING_ONLY"
  dynamic_substitutions = true
}

}
}

didnt work . Source has to go inside build {} .

Please paste a tested code .

Error: Missing required argument

│ with google_cloudbuild_trigger.namefilniltrig,
│ on manual.tf line 284, in resource “google_cloudbuild_trigger” “namefilniltrig”:
│ 284: resource “google_cloudbuild_trigger” “namefilniltrig” {

│ “github”: one of bitbucket_server_trigger_config,github,pubsub_config,repository_event_config,source_to_build,trigger_template,webhook_config must be
│ specified


│ Error: Missing required argument

│ with google_cloudbuild_trigger.namefilniltrig,
│ on manual.tf line 284, in resource “google_cloudbuild_trigger” “namefilniltrig”:
│ 284: resource “google_cloudbuild_trigger” “namefilniltrig” {

│ “bitbucket_server_trigger_config”: one of
bitbucket_server_trigger_config,github,pubsub_config,repository_event_config,source_to_build,trigger_template,webhook_config must be specified


│ Error: Missing required argument

│ with google_cloudbuild_trigger.namefilniltrig,
│ on manual.tf line 284, in resource “google_cloudbuild_trigger” “namefilniltrig”:
│ 284: resource “google_cloudbuild_trigger” “namefilniltrig” {

│ “trigger_template”: one of bitbucket_server_trigger_config,github,pubsub_config,repository_event_config,source_to_build,trigger_template,webhook_config
│ must be specified


│ Error: Missing required argument

│ with google_cloudbuild_trigger.namefilniltrig,
│ on manual.tf line 284, in resource “google_cloudbuild_trigger” “namefilniltrig”:
│ 284: resource “google_cloudbuild_trigger” “namefilniltrig” {

│ “webhook_config”: one of bitbucket_server_trigger_config,github,pubsub_config,repository_event_config,source_to_build,trigger_template,webhook_config
│ must be specified


│ Error: Missing required argument

│ with google_cloudbuild_trigger.namefilniltrig,
│ on manual.tf line 284, in resource “google_cloudbuild_trigger” “namefilniltrig”:
│ 284: resource “google_cloudbuild_trigger” “namefilniltrig” {

│ “pubsub_config”: one of bitbucket_server_trigger_config,github,pubsub_config,repository_event_config,source_to_build,trigger_template,webhook_config
│ must be specified


│ Error: Missing required argument

│ with google_cloudbuild_trigger.namefilniltrig,
│ on manual.tf line 284, in resource “google_cloudbuild_trigger” “namefilniltrig”:
│ 284: resource “google_cloudbuild_trigger” “namefilniltrig” {

│ “repository_event_config”: one of
bitbucket_server_trigger_config,github,pubsub_config,repository_event_config,source_to_build,trigger_template,webhook_config must be specified


│ Error: Missing required argument

│ with google_cloudbuild_trigger.namefilniltrig,
│ on manual.tf line 284, in resource “google_cloudbuild_trigger” “namefilniltrig”:
│ 284: resource “google_cloudbuild_trigger” “namefilniltrig” {

│ “source_to_build”: one of bitbucket_server_trigger_config,github,pubsub_config,repository_event_config,source_to_build,trigger_template,webhook_config
│ must be specified

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