Webhook
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.
Example Usage
Bitbucket and GitHub
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 this provider.
Note: The AWS account that this provider uses to create this resource must have authorized CodeBuild to access Bitbucket/GitHub's OAuth API in each applicable region. This is a manual step that must be done before creating webhooks with this resource. If OAuth is not configured, AWS will return an error similar to
ResourceNotFoundException: Could not find access token for server type github
. More information can be found in the CodeBuild User Guide for Bitbucket and GitHub. Note: Further managing the automatically created Bitbucket/GitHub webhook with thebitbucket_hook
/github_repository_webhook
resource is only possible with importing that resource after creation of theaws.codebuild.Webhook
resource. The CodeBuild API does not ever provide thesecret
attribute for theaws.codebuild.Webhook
resource in this scenario.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const example = new aws.codebuild.Webhook("example", {
projectName: exampleAwsCodebuildProject.name,
buildType: "BUILD",
filterGroups: [{
filters: [
{
type: "EVENT",
pattern: "PUSH",
},
{
type: "BASE_REF",
pattern: "master",
},
],
}],
});
import pulumi
import pulumi_aws as aws
example = aws.codebuild.Webhook("example",
project_name=example_aws_codebuild_project["name"],
build_type="BUILD",
filter_groups=[{
"filters": [
{
"type": "EVENT",
"pattern": "PUSH",
},
{
"type": "BASE_REF",
"pattern": "master",
},
],
}])
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var example = new Aws.CodeBuild.Webhook("example", new()
{
ProjectName = exampleAwsCodebuildProject.Name,
BuildType = "BUILD",
FilterGroups = new[]
{
new Aws.CodeBuild.Inputs.WebhookFilterGroupArgs
{
Filters = new[]
{
new Aws.CodeBuild.Inputs.WebhookFilterGroupFilterArgs
{
Type = "EVENT",
Pattern = "PUSH",
},
new Aws.CodeBuild.Inputs.WebhookFilterGroupFilterArgs
{
Type = "BASE_REF",
Pattern = "master",
},
},
},
},
});
});
package main
import (
"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/codebuild"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
_, err := codebuild.NewWebhook(ctx, "example", &codebuild.WebhookArgs{
ProjectName: pulumi.Any(exampleAwsCodebuildProject.Name),
BuildType: pulumi.String("BUILD"),
FilterGroups: codebuild.WebhookFilterGroupArray{
&codebuild.WebhookFilterGroupArgs{
Filters: codebuild.WebhookFilterGroupFilterArray{
&codebuild.WebhookFilterGroupFilterArgs{
Type: pulumi.String("EVENT"),
Pattern: pulumi.String("PUSH"),
},
&codebuild.WebhookFilterGroupFilterArgs{
Type: pulumi.String("BASE_REF"),
Pattern: pulumi.String("master"),
},
},
},
},
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.codebuild.Webhook;
import com.pulumi.aws.codebuild.WebhookArgs;
import com.pulumi.aws.codebuild.inputs.WebhookFilterGroupArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var example = new Webhook("example", WebhookArgs.builder()
.projectName(exampleAwsCodebuildProject.name())
.buildType("BUILD")
.filterGroups(WebhookFilterGroupArgs.builder()
.filters(
WebhookFilterGroupFilterArgs.builder()
.type("EVENT")
.pattern("PUSH")
.build(),
WebhookFilterGroupFilterArgs.builder()
.type("BASE_REF")
.pattern("master")
.build())
.build())
.build());
}
}
resources:
example:
type: aws:codebuild:Webhook
properties:
projectName: ${exampleAwsCodebuildProject.name}
buildType: BUILD
filterGroups:
- filters:
- type: EVENT
pattern: PUSH
- type: BASE_REF
pattern: master
GitHub Enterprise
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.
resources:
example:
type: aws:codebuild:Webhook
properties:
projectName: ${exampleAwsCodebuildProject.name}
exampleRepositoryWebhook:
type: github:RepositoryWebhook
name: example
properties:
active: true
events:
- push
name: example
repository: ${exampleGithubRepository.name}
configuration:
url: ${example.payloadUrl}
secret: ${example.secret}
contentType: json
insecureSsl: false
Import
Using pulumi import
, import CodeBuild Webhooks using the CodeBuild Project name. For example:
$ pulumi import aws:codebuild/webhook:Webhook example MyProjectName
Properties
A regular expression used to determine which branches get built. Default is all branches are built. We recommend using filter_group
over branch_filter
.
Information about the webhook's trigger. Filter group blocks are documented below.
If true, CodeBuild doesn't create a webhook in GitHub and instead returns payload_url
and secret
values for the webhook. The payload_url
and secret
values in the output can be used to manually create a webhook within GitHub.
The CodeBuild endpoint where webhook events are sent.
The name of the build project.
Scope configuration for global or organization webhooks. Scope configuration blocks are documented below.