Skip to content

googleCloudbuildTrigger

Configuration for an automated build in response to source repository changes.

To get more information about Trigger, see:

\~> Note: You can retrieve the email of the Cloud Build Service Account used in jobs by using the googleProjectServiceIdentity resource.

Example Usage - Cloudbuild Trigger Filename

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudbuildTrigger.CloudbuildTrigger(this, "filename-trigger", {
  filename: "cloudbuild.yaml",
  location: "us-central1",
  substitutions: [
    {
      _BAZ: "qux",
      _FOO: "bar",
    },
  ],
  trigger_template: [
    {
      branch_name: "main",
      repo_name: "my-repo",
    },
  ],
});

Example Usage - Cloudbuild Trigger Build

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudbuildTrigger.CloudbuildTrigger(this, "build-trigger", {
  build: [
    {
      artifacts: [
        {
          images: ["gcr.io/$PROJECT_ID/$REPO_NAME:$COMMIT_SHA"],
          objects: [
            {
              location: "gs://bucket/path/to/somewhere/",
              paths: ["path"],
            },
          ],
        },
      ],
      available_secrets: [
        {
          secret_manager: [
            {
              env: "MY_SECRET",
              version_name:
                "projects/myProject/secrets/mySecret/versions/latest",
            },
          ],
        },
      ],
      logs_bucket: "gs://mybucket/logs",
      options: [
        {
          disk_size_gb: 100,
          dynamic_substitutions: true,
          env: ["ekey = evalue"],
          log_streaming_option: "STREAM_OFF",
          logging: "LEGACY",
          machine_type: "N1_HIGHCPU_8",
          requested_verify_option: "VERIFIED",
          secret_env: ["secretenv = svalue"],
          source_provenance_hash: ["MD5"],
          substitution_option: "ALLOW_LOOSE",
          volumes: [
            {
              name: "v1",
              path: "v1",
            },
          ],
          worker_pool: "pool",
        },
      ],
      queue_ttl: "20s",
      secret: [
        {
          kms_key_name:
            "projects/myProject/locations/global/keyRings/keyring-name/cryptoKeys/key-name",
          secret_env: [
            {
              PASSWORD: "ZW5jcnlwdGVkLXBhc3N3b3JkCg==",
            },
          ],
        },
      ],
      source: [
        {
          storage_source: [
            {
              bucket: "mybucket",
              object: "source_code.tar.gz",
            },
          ],
        },
      ],
      step: [
        {
          args: ["cp", "gs://mybucket/remotefile.zip", "localfile.zip"],
          name: "gcr.io/cloud-builders/gsutil",
          secret_env: ["MY_SECRET"],
          timeout: "120s",
        },
        {
          name: "ubuntu",
          script: "echo hello",
        },
      ],
      substitutions: [
        {
          _BAZ: "qux",
          _FOO: "bar",
        },
      ],
      tags: ["build", "newFeature"],
    },
  ],
  location: "global",
  trigger_template: [
    {
      branch_name: "main",
      repo_name: "my-repo",
    },
  ],
});

Example Usage - Cloudbuild Trigger Service Account

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleServiceAccountCloudbuildServiceAccount =
  new google.serviceAccount.ServiceAccount(this, "cloudbuild_service_account", {
    account_id: "tf-test-my-service-account",
  });
const dataGoogleProjectProject = new google.dataGoogleProject.DataGoogleProject(
  this,
  "project",
  {}
);
const googleProjectIamMemberActAs =
  new google.projectIamMember.ProjectIamMember(this, "act_as", {
    member: `serviceAccount:\${${googleServiceAccountCloudbuildServiceAccount.email}}`,
    project: dataGoogleProjectProject.projectId,
    role: "roles/iam.serviceAccountUser",
  });
const googleProjectIamMemberLogsWriter =
  new google.projectIamMember.ProjectIamMember(this, "logs_writer", {
    member: `serviceAccount:\${${googleServiceAccountCloudbuildServiceAccount.email}}`,
    project: dataGoogleProjectProject.projectId,
    role: "roles/logging.logWriter",
  });
new google.cloudbuildTrigger.CloudbuildTrigger(
  this,
  "service-account-trigger",
  {
    depends_on: [
      `\${${googleProjectIamMemberActAs.fqn}}`,
      `\${${googleProjectIamMemberLogsWriter.fqn}}`,
    ],
    filename: "cloudbuild.yaml",
    service_account: googleServiceAccountCloudbuildServiceAccount.id,
    trigger_template: [
      {
        branch_name: "main",
        repo_name: "my-repo",
      },
    ],
  }
);

Example Usage - Cloudbuild Trigger Include Build Logs

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudbuildTrigger.CloudbuildTrigger(
  this,
  "include-build-logs-trigger",
  {
    filename: "cloudbuild.yaml",
    github: [
      {
        name: "terraform-provider-google-beta",
        owner: "hashicorp",
        push: [
          {
            branch: "^main$",
          },
        ],
      },
    ],
    include_build_logs: "INCLUDE_BUILD_LOGS_WITH_STATUS",
    location: "us-central1",
    name: "include-build-logs-trigger",
  }
);

Example Usage - Cloudbuild Trigger Pubsub Config

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googlePubsubTopicMytopic = new google.pubsubTopic.PubsubTopic(
  this,
  "mytopic",
  {
    name: "mytopic",
  }
);
new google.cloudbuildTrigger.CloudbuildTrigger(this, "pubsub-config-trigger", {
  description: "acceptance test example pubsub build trigger",
  filter: "_ACTION.matches('INSERT')",
  git_file_source: [
    {
      path: "cloudbuild.yaml",
      repo_type: "GITHUB",
      revision: "refs/heads/main",
      uri: "https://hashicorp/terraform-provider-google-beta",
    },
  ],
  location: "us-central1",
  name: "pubsub-trigger",
  pubsub_config: [
    {
      topic: googlePubsubTopicMytopic.id,
    },
  ],
  source_to_build: [
    {
      ref: "refs/heads/main",
      repo_type: "GITHUB",
      uri: "https://hashicorp/terraform-provider-google-beta",
    },
  ],
  substitutions: [
    {
      _ACTION: "$(body.message.data.action)",
    },
  ],
});

Example Usage - Cloudbuild Trigger Webhook Config

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleSecretManagerSecretWebhookTriggerSecretKey =
  new google.secretManagerSecret.SecretManagerSecret(
    this,
    "webhook_trigger_secret_key",
    {
      replication: [
        {
          user_managed: [
            {
              replicas: [
                {
                  location: "us-central1",
                },
              ],
            },
          ],
        },
      ],
      secret_id: "webhook_trigger-secret-key-1",
    }
  );
const googleSecretManagerSecretVersionWebhookTriggerSecretKeyData =
  new google.secretManagerSecretVersion.SecretManagerSecretVersion(
    this,
    "webhook_trigger_secret_key_data",
    {
      secret: googleSecretManagerSecretWebhookTriggerSecretKey.id,
      secret_data: "secretkeygoeshere",
    }
  );
const dataGoogleProjectProject = new google.dataGoogleProject.DataGoogleProject(
  this,
  "project",
  {}
);
new google.cloudbuildTrigger.CloudbuildTrigger(this, "webhook-config-trigger", {
  description: "acceptance test example webhook build trigger",
  git_file_source: [
    {
      path: "cloudbuild.yaml",
      repo_type: "GITHUB",
      revision: "refs/heads/main",
      uri: "https://hashicorp/terraform-provider-google-beta",
    },
  ],
  name: "webhook-trigger",
  source_to_build: [
    {
      ref: "refs/heads/main",
      repo_type: "GITHUB",
      uri: "https://hashicorp/terraform-provider-google-beta",
    },
  ],
  webhook_config: [
    {
      secret: googleSecretManagerSecretVersionWebhookTriggerSecretKeyData.id,
    },
  ],
});
const dataGoogleIamPolicySecretAccessor =
  new google.dataGoogleIamPolicy.DataGoogleIamPolicy(this, "secret_accessor", {
    binding: [
      {
        members: [
          `serviceAccount:service-\${${dataGoogleProjectProject.number}}@gcp-sa-cloudbuild.iam.gserviceaccount.com`,
        ],
        role: "roles/secretmanager.secretAccessor",
      },
    ],
  });
new google.secretManagerSecretIamPolicy.SecretManagerSecretIamPolicy(
  this,
  "policy",
  {
    policy_data: dataGoogleIamPolicySecretAccessor.policyData,
    project: googleSecretManagerSecretWebhookTriggerSecretKey.project,
    secret_id: googleSecretManagerSecretWebhookTriggerSecretKey.secretId,
  }
);

Example Usage - Cloudbuild Trigger Manual

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudbuildTrigger.CloudbuildTrigger(this, "manual-trigger", {
  approval_config: [
    {
      approval_required: true,
    },
  ],
  git_file_source: [
    {
      path: "cloudbuild.yaml",
      repo_type: "GITHUB",
      revision: "refs/heads/main",
      uri: "https://hashicorp/terraform-provider-google-beta",
    },
  ],
  name: "manual-build",
  source_to_build: [
    {
      ref: "refs/heads/main",
      repo_type: "GITHUB",
      uri: "https://hashicorp/terraform-provider-google-beta",
    },
  ],
});

Example Usage - Cloudbuild Trigger Manual Github Enterprise

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudbuildTrigger.CloudbuildTrigger(this, "manual-ghe-trigger", {
  git_file_source: [
    {
      github_enterprise_config:
        "projects/myProject/locations/global/githubEnterpriseConfigs/configID",
      path: "cloudbuild.yaml",
      repo_type: "GITHUB",
      revision: "refs/heads/main",
      uri: "https://hashicorp/terraform-provider-google-beta",
    },
  ],
  name: "terraform-manual-ghe-trigger",
  source_to_build: [
    {
      github_enterprise_config:
        "projects/myProject/locations/global/githubEnterpriseConfigs/configID",
      ref: "refs/heads/main",
      repo_type: "GITHUB",
      uri: "https://hashicorp/terraform-provider-google-beta",
    },
  ],
});

Example Usage - Cloudbuild Trigger Repo

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
const googleCloudbuildv2ConnectionMyConnection =
  new google.cloudbuildv2Connection.Cloudbuildv2Connection(
    this,
    "my-connection",
    {
      github_config: [
        {
          app_installation_id: 123123,
          authorizer_credential: [
            {
              oauth_token_secret_version:
                "projects/my-project/secrets/github-pat-secret/versions/latest",
            },
          ],
        },
      ],
      location: "us-central1",
      name: "my-connection",
      provider: "${google-beta}",
    }
  );
const googleCloudbuildv2RepositoryMyRepository =
  new google.cloudbuildv2Repository.Cloudbuildv2Repository(
    this,
    "my-repository",
    {
      name: "my-repo",
      parent_connection: googleCloudbuildv2ConnectionMyConnection.id,
      provider: "${google-beta}",
      remote_uri: "https://github.com/myuser/my-repo.git",
    }
  );
new google.cloudbuildTrigger.CloudbuildTrigger(this, "repo-trigger", {
  filename: "cloudbuild.yaml",
  location: "us-central1",
  provider: "${google-beta}",
  repository_event_config: [
    {
      push: [
        {
          branch: "feature-.*",
        },
      ],
      repository: googleCloudbuildv2RepositoryMyRepository.id,
    },
  ],
});

Example Usage - Cloudbuild Trigger Bitbucket Server Push

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudbuildTrigger.CloudbuildTrigger(this, "bbs-push-trigger", {
  bitbucket_server_trigger_config: [
    {
      bitbucket_server_config_resource:
        "projects/123456789/locations/us-central1/bitbucketServerConfigs/myBitbucketConfig",
      project_key: "STAG",
      push: [
        {
          invert_regex: true,
          tag: "^0.1.*",
        },
      ],
      repo_slug: "terraform-provider-google",
    },
  ],
  filename: "cloudbuild.yaml",
  location: "us-central1",
  name: "terraform-bbs-push-trigger",
});

Example Usage - Cloudbuild Trigger Bitbucket Server Pull Request

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudbuildTrigger.CloudbuildTrigger(
  this,
  "bbs-pull-request-trigger",
  {
    bitbucket_server_trigger_config: [
      {
        bitbucket_server_config_resource:
          "projects/123456789/locations/us-central1/bitbucketServerConfigs/myBitbucketConfig",
        project_key: "STAG",
        pull_request: [
          {
            branch: "^master$",
            comment_control: "COMMENTS_ENABLED",
            invert_regex: false,
          },
        ],
        repo_slug: "terraform-provider-google",
      },
    ],
    filename: "cloudbuild.yaml",
    location: "us-central1",
    name: "terraform-bbs-pull-request-trigger",
  }
);

Example Usage - Cloudbuild Trigger Github Enterprise

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as google from "./.gen/providers/google";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: google.
For a more precise conversion please use the --provider flag in convert.*/
new google.cloudbuildTrigger.CloudbuildTrigger(this, "ghe-trigger", {
  filename: "cloudbuild.yaml",
  github: [
    {
      enterprise_config_resource_name:
        "projects/123456789/locations/us-central1/githubEnterpriseConfigs/configID",
      name: "terraform-provider-google",
      owner: "hashicorp",
      push: [
        {
          branch: "^main$",
        },
      ],
    },
  ],
  location: "us-central1",
  name: "terraform-ghe-trigger",
});

Argument Reference

The following arguments are supported:


  • name - (Optional) Name of the trigger. Must be unique within the project.

  • description - (Optional) Human-readable description of the trigger.

  • tags - (Optional) Tags for annotation of a BuildTrigger

  • disabled - (Optional) Whether the trigger is disabled or not. If true, the trigger will never result in a build.

  • substitutions - (Optional) Substitutions data for Build resource.

  • serviceAccount - (Optional) The service account used for all user-controlled operations including triggers.patch, triggers.run, builds.create, and builds.cancel. If no service account is set, then the standard Cloud Build service account ([PROJECT_NUM]@system.gserviceaccount.com) will be used instead. Format: projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT_ID_OR_EMAIL}

  • includeBuildLogs - (Optional) Build logs will be sent back to GitHub as part of the checkrun result. Values can be INCLUDE_BUILD_LOGS_UNSPECIFIED or INCLUDE_BUILD_LOGS_WITH_STATUS Possible values are includeBuildLogsUnspecified and includeBuildLogsWithStatus.

  • filename - (Optional) Path, from the source root, to a file whose contents is used for the template. Either a filename or build template must be provided. Set this only when using trigger_template or github. When using Pub/Sub, Webhook or Manual set the file name using git_file_source instead.

  • filter - (Optional) A Common Expression Language string. Used only with Pub/Sub and Webhook.

  • gitFileSource - (Optional) The file source describing the local or remote Build template. Structure is documented below.

  • repositoryEventConfig - (Optional, Beta) The configuration of a trigger that creates a build whenever an event from Repo API is received. Structure is documented below.

  • sourceToBuild - (Optional) The repo and ref of the repository from which to build. This field is used only for those triggers that do not respond to SCM events. Triggers that respond to such events build source at whatever commit caused the event. This field is currently only used by Webhook, Pub/Sub, Manual, and Cron triggers. One of triggerTemplate, github, pubsubConfig webhookConfig or sourceToBuild must be provided. Structure is documented below.

  • ignoredFiles - (Optional) ignoredFiles and includedFiles are file glob matches using https://golang.org/pkg/path/filepath/#Match extended with support for **. If ignoredFiles and changed files are both empty, then they are not used to determine whether or not to trigger a build. If ignoredFiles is not empty, then we ignore any files that match any of the ignored_file globs. If the change has no files that are outside of the ignoredFiles globs, then we do not trigger a build.

  • includedFiles - (Optional) ignoredFiles and includedFiles are file glob matches using https://golang.org/pkg/path/filepath/#Match extended with support for **. If any of the files altered in the commit pass the ignoredFiles filter and includedFiles is empty, then as far as this filter is concerned, we should trigger the build. If any of the files altered in the commit pass the ignoredFiles filter and includedFiles is not empty, then we make sure that at least one of those files matches a includedFiles glob. If not, then we do not trigger a build.

  • triggerTemplate - (Optional) Template describing the types of source changes to trigger a build. Branch and tag names in trigger templates are interpreted as regular expressions. Any branch or tag change that matches that regular expression will trigger a build. One of triggerTemplate, github, pubsubConfig, webhookConfig or sourceToBuild must be provided. Structure is documented below.

  • github - (Optional) Describes the configuration of a trigger that creates a build whenever a GitHub event is received. One of triggerTemplate, github, pubsubConfig or webhookConfig must be provided. Structure is documented below.

  • bitbucketServerTriggerConfig - (Optional) BitbucketServerTriggerConfig describes the configuration of a trigger that creates a build whenever a Bitbucket Server event is received. Structure is documented below.

  • pubsubConfig - (Optional) PubsubConfig describes the configuration of a trigger that creates a build whenever a Pub/Sub message is published. One of triggerTemplate, github, pubsubConfig webhookConfig or sourceToBuild must be provided. Structure is documented below.

  • webhookConfig - (Optional) WebhookConfig describes the configuration of a trigger that creates a build whenever a webhook is sent to a trigger's webhook URL. One of triggerTemplate, github, pubsubConfig webhookConfig or sourceToBuild must be provided. Structure is documented below.

  • approvalConfig - (Optional) Configuration for manual approval to start a build invocation of this BuildTrigger. Builds created by this trigger will require approval before they execute. Any user with a Cloud Build Approver role for the project can approve a build. Structure is documented below.

  • build - (Optional) Contents of the build template. Either a filename or build template must be provided. Structure is documented below.

  • location - (Optional) The Cloud Build location for the trigger. If not specified, "global" is used.

  • project - (Optional) The ID of the project in which the resource belongs. If it is not provided, the provider project is used.

The gitFileSource block supports:

  • path - (Required) The path of the file, with the repo root as the root of the path.

  • uri - (Optional) The URI of the repo (optional). If unspecified, the repo from which the trigger invocation originated is assumed to be the repo from which to read the specified path.

  • repoType - (Required) The type of the repo, since it may not be explicit from the repo field (e.g from a URL). Values can be UNKNOWN, CLOUD_SOURCE_REPOSITORIES, GITHUB, BITBUCKET_SERVER Possible values are unknown, cloudSourceRepositories, github, and bitbucketServer.

  • revision - (Optional) The branch, tag, arbitrary ref, or SHA version of the repo to use when resolving the filename (optional). This field respects the same syntax/resolution as described here: https://git-scm.com/docs/gitrevisions If unspecified, the revision from which the trigger invocation originated is assumed to be the revision from which to read the specified path.

  • githubEnterpriseConfig - (Optional) The full resource name of the github enterprise config. Format: projects/{project}/locations/{location}/githubEnterpriseConfigs/{id}. projects/{project}/githubEnterpriseConfigs/{id}.

The repositoryEventConfig block supports:

  • repository - (Optional) The resource name of the Repo API resource.

  • pullRequest - (Optional) Contains filter properties for matching Pull Requests. Structure is documented below.

  • push - (Optional) Contains filter properties for matching git pushes. Structure is documented below.

The pullRequest block supports:

  • branch - (Optional) Regex of branches to match. The syntax of the regular expressions accepted is the syntax accepted by RE2 and described at https://github.com/google/re2/wiki/Syntax

  • invertRegex - (Optional) If true, branches that do NOT match the git_ref will trigger a build.

  • commentControl - (Optional) Configure builds to run whether a repository owner or collaborator need to comment /gcbrun. Possible values are commentsDisabled, commentsEnabled, and commentsEnabledForExternalContributorsOnly.

The push block supports:

  • branch - (Optional) Regex of branches to match. The syntax of the regular expressions accepted is the syntax accepted by RE2 and described at https://github.com/google/re2/wiki/Syntax

  • tag - (Optional) Regex of tags to match. The syntax of the regular expressions accepted is the syntax accepted by RE2 and described at https://github.com/google/re2/wiki/Syntax

  • invertRegex - (Optional) If true, only trigger a build if the revision regex does NOT match the git_ref regex.

The sourceToBuild block supports:

  • uri - (Required) The URI of the repo (required).

  • ref - (Required) The branch or tag to use. Must start with "refs/" (required).

  • repoType - (Required) The type of the repo, since it may not be explicit from the repo field (e.g from a URL). Values can be UNKNOWN, CLOUD_SOURCE_REPOSITORIES, GITHUB, BITBUCKET_SERVER Possible values are unknown, cloudSourceRepositories, github, and bitbucketServer.

  • githubEnterpriseConfig - (Optional) The full resource name of the github enterprise config. Format: projects/{project}/locations/{location}/githubEnterpriseConfigs/{id}. projects/{project}/githubEnterpriseConfigs/{id}.

The triggerTemplate block supports:

  • projectId - (Optional) ID of the project that owns the Cloud Source Repository. If omitted, the project ID requesting the build is assumed.

  • repoName - (Optional) Name of the Cloud Source Repository. If omitted, the name "default" is assumed.

  • dir - (Optional) Directory, relative to the source root, in which to run the build. This must be a relative path. If a step's dir is specified and is an absolute path, this value is ignored for that step's execution.

  • invertRegex - (Optional) Only trigger a build if the revision regex does NOT match the revision regex.

  • branchName - (Optional) Name of the branch to build. Exactly one a of branch name, tag, or commit SHA must be provided. This field is a regular expression.

  • tagName - (Optional) Name of the tag to build. Exactly one of a branch name, tag, or commit SHA must be provided. This field is a regular expression.

  • commitSha - (Optional) Explicit commit SHA to build. Exactly one of a branch name, tag, or commit SHA must be provided.

The github block supports:

  • owner - (Optional) Owner of the repository. For example: The owner for https://github.com/googlecloudplatform/cloud-builders is "googlecloudplatform".

  • name - (Optional) Name of the repository. For example: The name for https://github.com/googlecloudplatform/cloud-builders is "cloud-builders".

  • pullRequest - (Optional) filter to match changes in pull requests. Specify only one of pullRequest or push. Structure is documented below.

  • push - (Optional) filter to match changes in refs, like branches or tags. Specify only one of pullRequest or push. Structure is documented below.

  • enterpriseConfigResourceName - (Optional) The resource name of the github enterprise config that should be applied to this installation. For example: "projects/{$projectId}/locations/{$locationId}/githubEnterpriseConfigs/{$configId}"

The pullRequest block supports:

  • branch - (Required) Regex of branches to match.

  • commentControl - (Optional) Whether to block builds on a "/gcbrun" comment from a repository owner or collaborator. Possible values are commentsDisabled, commentsEnabled, and commentsEnabledForExternalContributorsOnly.

  • invertRegex - (Optional) If true, branches that do NOT match the git_ref will trigger a build.

The push block supports:

  • invertRegex - (Optional) When true, only trigger a build if the revision regex does NOT match the git_ref regex.

  • branch - (Optional) Regex of branches to match. Specify only one of branch or tag.

  • tag - (Optional) Regex of tags to match. Specify only one of branch or tag.

The bitbucketServerTriggerConfig block supports:

  • repoSlug - (Required) Slug of the repository. A repository slug is a URL-friendly version of a repository name, automatically generated by Bitbucket for use in the URL. For example, if the repository name is 'test repo', in the URL it would become 'test-repo' as in https://mybitbucket.server/projects/TEST/repos/test-repo.

  • projectKey - (Required) Key of the project that the repo is in. For example: The key for https://mybitbucket.server/projects/TEST/repos/test-repo is "TEST".

  • bitbucketServerConfigResource - (Required) The Bitbucket server config resource that this trigger config maps to.

  • pullRequest - (Optional) Filter to match changes in pull requests. Structure is documented below.

  • push - (Optional) Filter to match changes in refs like branches, tags. Structure is documented below.

The pullRequest block supports:

  • branch - (Required) Regex of branches to match. The syntax of the regular expressions accepted is the syntax accepted by RE2 and described at https://github.com/google/re2/wiki/Syntax

  • commentControl - (Optional) Configure builds to run whether a repository owner or collaborator need to comment /gcbrun. Possible values are commentsDisabled, commentsEnabled, and commentsEnabledForExternalContributorsOnly.

  • invertRegex - (Optional) If true, branches that do NOT match the git_ref will trigger a build.

The push block supports:

  • invertRegex - (Optional) When true, only trigger a build if the revision regex does NOT match the gitRef regex.

  • branch - (Optional) Regex of branches to match. Specify only one of branch or tag.

  • tag - (Optional) Regex of tags to match. Specify only one of branch or tag.

The pubsubConfig block supports:

  • subscription - (Output) Output only. Name of the subscription.

  • topic - (Required) The name of the topic from which this subscription is receiving messages.

  • serviceAccountEmail - (Optional) Service account that will make the push request.

  • state - (Output) Potential issues with the underlying Pub/Sub subscription configuration. Only populated on get requests.

The webhookConfig block supports:

  • secret - (Required) Resource name for the secret required as a URL parameter.

  • state - (Output) Potential issues with the underlying Pub/Sub subscription configuration. Only populated on get requests.

The approvalConfig block supports:

  • approvalRequired - (Optional) Whether or not approval is needed. If this is set on a build, it will become pending when run, and will need to be explicitly approved to start.

The build block supports:

  • source - (Optional) The location of the source files to build. One of storageSource or repoSource must be provided. Structure is documented below.

  • tags - (Optional) Tags for annotation of a Build. These are not docker tags.

  • images - (Optional) A list of images to be pushed upon the successful completion of all build steps. The images are pushed using the builder service account's credentials. The digests of the pushed images will be stored in the Build resource's results field. If any of the images fail to be pushed, the build status is marked FAILURE.

  • substitutions - (Optional) Substitutions data for Build resource.

  • queueTtl - (Optional) TTL in queue for this build. If provided and the build is enqueued longer than this value, the build will expire and the build status will be EXPIRED. The TTL starts ticking from createTime. A duration in seconds with up to nine fractional digits, terminated by 's'. Example: "3.5s".

  • logsBucket - (Optional) Google Cloud Storage bucket where logs should be written. Logs file names will be of the format ${logsBucket}/log-${build_id}.txt.

  • timeout - (Optional) Amount of time that this build should be allowed to run, to second granularity. If this amount of time elapses, work on the build will cease and the build status will be TIMEOUT. This timeout must be equal to or greater than the sum of the timeouts for build steps within the build. The expected format is the number of seconds followed by s. Default time is ten minutes (600s).

  • secret - (Optional) Secrets to decrypt using Cloud Key Management Service. Structure is documented below.

  • availableSecrets - (Optional) Secrets and secret environment variables. Structure is documented below.

  • step - (Required) The operations to be performed on the workspace. Structure is documented below.

  • artifacts - (Optional) Artifacts produced by the build that should be uploaded upon successful completion of all build steps. Structure is documented below.

  • options - (Optional) Special options for this build. Structure is documented below.

The source block supports:

  • storageSource - (Optional) Location of the source in an archive file in Google Cloud Storage. Structure is documented below.

  • repoSource - (Optional) Location of the source in a Google Cloud Source Repository. Structure is documented below.

The storageSource block supports:

  • bucket - (Required) Google Cloud Storage bucket containing the source.

  • object - (Required) Google Cloud Storage object containing the source. This object must be a gzipped archive file (.tar.gz) containing source to build.

  • generation - (Optional) Google Cloud Storage generation for the object. If the generation is omitted, the latest generation will be used

The repoSource block supports:

  • projectId - (Optional) ID of the project that owns the Cloud Source Repository. If omitted, the project ID requesting the build is assumed.

  • repoName - (Required) Name of the Cloud Source Repository.

  • dir - (Optional) Directory, relative to the source root, in which to run the build. This must be a relative path. If a step's dir is specified and is an absolute path, this value is ignored for that step's execution.

  • invertRegex - (Optional) Only trigger a build if the revision regex does NOT match the revision regex.

  • substitutions - (Optional) Substitutions to use in a triggered build. Should only be used with triggers.run

  • branchName - (Optional) Regex matching branches to build. Exactly one a of branch name, tag, or commit SHA must be provided. The syntax of the regular expressions accepted is the syntax accepted by RE2 and described at https://github.com/google/re2/wiki/Syntax

  • tagName - (Optional) Regex matching tags to build. Exactly one a of branch name, tag, or commit SHA must be provided. The syntax of the regular expressions accepted is the syntax accepted by RE2 and described at https://github.com/google/re2/wiki/Syntax

  • commitSha - (Optional) Explicit commit SHA to build. Exactly one a of branch name, tag, or commit SHA must be provided.

The secret block supports:

  • kmsKeyName - (Required) Cloud KMS key name to use to decrypt these envs.

  • secretEnv - (Optional) Map of environment variable name to its encrypted value. Secret environment variables must be unique across all of a build's secrets, and must be used by at least one build step. Values can be at most 64 KB in size. There can be at most 100 secret values across all of a build's secrets.

The availableSecrets block supports:

  • secretManager - (Required) Pairs a secret environment variable with a SecretVersion in Secret Manager. Structure is documented below.

The secretManager block supports:

  • versionName - (Required) Resource name of the SecretVersion. In format: projects//secrets//versions/*

  • env - (Required) Environment variable name to associate with the secret. Secret environment variables must be unique across all of a build's secrets, and must be used by at least one build step.

The step block supports:

  • name - (Required) The name of the container image that will run this particular build step. If the image is available in the host's Docker daemon's cache, it will be run directly. If not, the host will attempt to pull the image first, using the builder service account's credentials if necessary. The Docker daemon's cache will already have the latest versions of all of the officially supported build steps (see https://github.com/GoogleCloudPlatform/cloud-builders for images and examples). The Docker daemon will also have cached many of the layers for some popular images, like "ubuntu", "debian", but they will be refreshed at the time you attempt to use them. If you built an image in a previous build step, it will be stored in the host's Docker daemon's cache and is available to use as the name for a later build step.

  • args - (Optional) A list of arguments that will be presented to the step when it is started. If the image used to run the step's container has an entrypoint, the args are used as arguments to that entrypoint. If the image does not define an entrypoint, the first element in args is used as the entrypoint, and the remainder will be used as arguments.

  • env - (Optional) A list of environment variable definitions to be used when running a step. The elements are of the form "KEY=VALUE" for the environment variable "KEY" being given the value "VALUE".

  • id - (Optional) Unique identifier for this build step, used in waitFor to reference this build step as a dependency.

  • entrypoint - (Optional) Entrypoint to be used instead of the build step image's default entrypoint. If unset, the image's default entrypoint is used

  • dir - (Optional) Working directory to use when running this step's container. If this value is a relative path, it is relative to the build's working directory. If this value is absolute, it may be outside the build's working directory, in which case the contents of the path may not be persisted across build step executions, unless a volume for that path is specified. If the build specifies a repoSource with dir and a step with a dir, which specifies an absolute path, the repoSource dir is ignored for the step's execution.

  • secretEnv - (Optional) A list of environment variables which are encrypted using a Cloud Key Management Service crypto key. These values must be specified in the build's secret.

  • timeout - (Optional) Time limit for executing this build step. If not defined, the step has no time limit and will be allowed to continue to run until either it completes or the build itself times out.

  • timing - (Optional) Output only. Stores timing information for executing this build step.

  • volumes - (Optional) List of volumes to mount into the build step. Each volume is created as an empty volume prior to execution of the build step. Upon completion of the build, volumes and their contents are discarded. Using a named volume in only one step is not valid as it is indicative of a build request with an incorrect configuration. Structure is documented below.

  • waitFor - (Optional) The ID(s) of the step(s) that this build step depends on. This build step will not start until all the build steps in waitFor have completed successfully. If waitFor is empty, this build step will start when all previous build steps in the buildSteps list have completed successfully.

  • script - (Optional) A shell script to be executed in the step. When script is provided, the user cannot specify the entrypoint or args.

The volumes block supports:

  • name - (Required) Name of the volume to mount. Volume names must be unique per build step and must be valid names for Docker volumes. Each named volume must be used by at least two build steps.

  • path - (Required) Path at which to mount the volume. Paths must be absolute and cannot conflict with other volume paths on the same build step or with certain reserved volume paths.

The artifacts block supports:

  • images - (Optional) A list of images to be pushed upon the successful completion of all build steps. The images will be pushed using the builder service account's credentials. The digests of the pushed images will be stored in the Build resource's results field. If any of the images fail to be pushed, the build is marked FAILURE.

  • objects - (Optional) A list of objects to be uploaded to Cloud Storage upon successful completion of all build steps. Files in the workspace matching specified paths globs will be uploaded to the Cloud Storage location using the builder service account's credentials. The location and generation of the uploaded objects will be stored in the Build resource's results field. If any objects fail to be pushed, the build is marked FAILURE. Structure is documented below.

The objects block supports:

  • location - (Optional) Cloud Storage bucket and optional object path, in the form "gs://bucket/path/to/somewhere/". Files in the workspace matching any path pattern will be uploaded to Cloud Storage with this location as a prefix.

  • paths - (Optional) Path globs used to match files in the build's workspace.

  • timing - (Output) Output only. Stores timing information for pushing all artifact objects. Structure is documented below.

The timing block contains:

  • startTime - (Optional) Start of time span. A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".

  • endTime - (Optional) End of time span. A timestamp in RFC3339 UTC "Zulu" format, with nanosecond resolution and up to nine fractional digits. Examples: "2014-10-02T15:01:23Z" and "2014-10-02T15:01:23.045123456Z".

The options block supports:

  • sourceProvenanceHash - (Optional) Requested hash for SourceProvenance. Each value may be one of none, sha256, and md5.

  • requestedVerifyOption - (Optional) Requested verifiability options. Possible values are notVerified and verified.

  • machineType - (Optional) Compute Engine machine type on which to run the build. Possible values are unspecified, n1Highcpu8, n1Highcpu32, e2Highcpu8, and e2Highcpu32.

  • diskSizeGb - (Optional) Requested disk size for the VM that runs the build. Note that this is NOT "disk free"; some of the space will be used by the operating system and build utilities. Also note that this is the minimum disk size that will be allocated for the build -- the build may run with a larger disk than requested. At present, the maximum disk size is 1000GB; builds that request more than the maximum are rejected with an error.

  • substitutionOption - (Optional) Option to specify behavior when there is an error in the substitution checks. NOTE this is always set to ALLOW_LOOSE for triggered builds and cannot be overridden in the build configuration file. Possible values are mustMatch and allowLoose.

  • dynamicSubstitutions - (Optional) Option to specify whether or not to apply bash style string operations to the substitutions. NOTE this is always enabled for triggered builds and cannot be overridden in the build configuration file.

  • logStreamingOption - (Optional) Option to define build log streaming behavior to Google Cloud Storage. Possible values are streamDefault, streamOn, and streamOff.

  • workerPool - (Optional) Option to specify a WorkerPool for the build. Format projects/{project}/workerPools/{workerPool} This field is experimental.

  • logging - (Optional) Option to specify the logging mode, which determines if and where build logs are stored. Possible values are loggingUnspecified, legacy, gcsOnly, stackdriverOnly, cloudLoggingOnly, and none.

  • env - (Optional) A list of global environment variable definitions that will exist for all build steps in this build. If a variable is defined in both globally and in a build step, the variable will use the build step value. The elements are of the form "KEY=VALUE" for the environment variable "KEY" being given the value "VALUE".

  • secretEnv - (Optional) A list of global environment variables, which are encrypted using a Cloud Key Management Service crypto key. These values must be specified in the build's Secret. These variables will be available to all build steps in this build.

  • volumes - (Optional) Global list of volumes to mount for ALL build steps Each volume is created as an empty volume prior to starting the build process. Upon completion of the build, volumes and their contents are discarded. Global volume names and paths cannot conflict with the volumes defined a build step. Using a global volume in a build with only one step is not valid as it is indicative of a build request with an incorrect configuration. Structure is documented below.

The volumes block supports:

  • name - (Optional) Name of the volume to mount. Volume names must be unique per build step and must be valid names for Docker volumes. Each named volume must be used by at least two build steps.

  • path - (Optional) Path at which to mount the volume. Paths must be absolute and cannot conflict with other volume paths on the same build step or with certain reserved volume paths.

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

  • id - an identifier for the resource with format projects/{{project}}/locations/{{location}}/triggers/{{triggerId}}

  • triggerId - The unique identifier for the trigger.

  • createTime - Time when the trigger was created.

Timeouts

This resource provides the following Timeouts configuration options:

  • create - Default is 20 minutes.
  • update - Default is 20 minutes.
  • delete - Default is 20 minutes.

Import

Trigger can be imported using any of these accepted formats:

$ terraform import google_cloudbuild_trigger.default projects/{{project}}/locations/{{location}}/triggers/{{trigger_id}}
$ terraform import google_cloudbuild_trigger.default projects/{{project}}/triggers/{{trigger_id}}
$ terraform import google_cloudbuild_trigger.default {{project}}/{{trigger_id}}
$ terraform import google_cloudbuild_trigger.default {{trigger_id}}

User Project Overrides

This resource supports User Project Overrides.