Manages a CodeBuild webhook, which is an endpoint accepted by the CodeBuild service to trigger builds from source code repositories. Depending on the source type of the CodeBuild project, the CodeBuild service may also automatically create and delete the actual repository webhook as well.
When working with Bitbucket and GitHub source CodeBuild webhooks, the CodeBuild service will automatically create (on aws_codebuild_webhook
resource creation) and delete (on aws_codebuild_webhook
resource deletion) the Bitbucket/GitHub repository webhook using its granted OAuth permissions. This behavior cannot be controlled by Terraform.
resource "aws_codebuild_webhook" "example" {
project_name = aws_codebuild_project.example.name
build_type = "BUILD"
filter_group {
filter {
type = "EVENT"
pattern = "PUSH"
}
filter {
type = "BASE_REF"
pattern = "master"
}
}
}
When working with GitHub Enterprise source CodeBuild webhooks, the GHE repository webhook must be separately managed (e.g., manually or with the github_repository_webhook
resource).
More information creating webhooks with GitHub Enterprise can be found in the CodeBuild User Guide.
resource "aws_codebuild_webhook" "example" {
project_name = aws_codebuild_project.example.name
}
resource "github_repository_webhook" "example" {
active = true
events = ["push"]
name = "example"
repository = github_repository.example.name
configuration {
url = aws_codebuild_webhook.example.payload_url
secret = aws_codebuild_webhook.example.secret
content_type = "json"
insecure_ssl = false
}
}
This resource supports the following arguments:
project_name
- (Required) The name of the build project.build_type
- (Optional) The type of build this webhook will trigger. Valid values for this parameter are: BUILD
, BUILD_BATCH
.branch_filter
- (Optional) A regular expression used to determine which branches get built. Default is all branches are built. We recommend using filter_group
over branch_filter
.filter_group
- (Optional) Information about the webhook's trigger. Filter group blocks are documented below.filter_group
supports the following:
filter
- (Required) A webhook filter for the group. Filter blocks are documented below.filter
supports the following:
type
- (Required) The webhook filter group's type. Valid values for this parameter are: EVENT
, BASE_REF
, HEAD_REF
, ACTOR_ACCOUNT_ID
, FILE_PATH
, COMMIT_MESSAGE
, WORKFLOW_NAME
, TAG_NAME
, RELEASE_NAME
. At least one filter group must specify EVENT
as its type.pattern
- (Required) For a filter that uses EVENT
type, a comma-separated string that specifies one event: PUSH
, PULL_REQUEST_CREATED
, PULL_REQUEST_UPDATED
, PULL_REQUEST_REOPENED
. PULL_REQUEST_MERGED
works with GitHub & GitHub Enterprise only. For a filter that uses any of the other filter types, a regular expression.exclude_matched_pattern
- (Optional) If set to true
, the specified filter does not trigger a build. Defaults to false
.This resource exports the following attributes in addition to the arguments above:
id
- The name of the build project.payload_url
- The CodeBuild endpoint where webhook events are sent.secret
- The secret token of the associated repository. Not returned by the CodeBuild API for all source types.url
- The URL to the webhook.In Terraform v1.5.0 and later, use an import
block to import CodeBuild Webhooks using the CodeBuild Project name. For example:
import {
to = aws_codebuild_webhook.example
id = "MyProjectName"
}
Using terraform import
, import CodeBuild Webhooks using the CodeBuild Project name. For example:
% terraform import aws_codebuild_webhook.example MyProjectName