Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter build_type to codebuild_webhook #20480

Merged
merged 6 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions aws/resource_aws_codebuild_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func resourceAwsCodeBuildWebhook() *schema.Resource {
Required: true,
ForceNew: true,
},
"build_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
codebuild.WebhookBuildTypeBuild,
codebuild.WebhookBuildTypeBuildBatch,
}, false),
},
"branch_filter": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -98,6 +106,10 @@ func resourceAwsCodeBuildWebhookCreate(d *schema.ResourceData, meta interface{})
FilterGroups: expandWebhookFilterGroups(d),
}

if v, ok := d.GetOk("build_type"); ok {
input.BuildType = aws.String(v.(string))
}

// The CodeBuild API requires this to be non-empty if defined
if v, ok := d.GetOk("branch_filter"); ok {
input.BranchFilter = aws.String(v.(string))
Expand Down Expand Up @@ -180,6 +192,7 @@ func resourceAwsCodeBuildWebhookRead(d *schema.ResourceData, meta interface{}) e
return nil
}

d.Set("build_type", project.Webhook.BuildType)
d.Set("branch_filter", project.Webhook.BranchFilter)
d.Set("filter_group", flattenAwsCodeBuildWebhookFilterGroups(project.Webhook.FilterGroups))
d.Set("payload_url", project.Webhook.PayloadUrl)
Expand All @@ -199,12 +212,14 @@ func resourceAwsCodeBuildWebhookUpdate(d *schema.ResourceData, meta interface{})
if len(filterGroups) >= 1 {
_, err = conn.UpdateWebhook(&codebuild.UpdateWebhookInput{
ProjectName: aws.String(d.Id()),
BuildType: aws.String(d.Get("build_type").(string)),
FilterGroups: filterGroups,
RotateSecret: aws.Bool(false),
})
} else {
_, err = conn.UpdateWebhook(&codebuild.UpdateWebhookInput{
ProjectName: aws.String(d.Id()),
BuildType: aws.String(d.Get("build_type").(string)),
BranchFilter: aws.String(d.Get("branch_filter").(string)),
RotateSecret: aws.Bool(false),
})
Expand Down
44 changes: 44 additions & 0 deletions aws/resource_aws_codebuild_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,41 @@ func TestAccAWSCodeBuildWebhook_GitHubEnterprise(t *testing.T) {
})
}

func TestAccAWSCodeBuildWebhook_BuildType(t *testing.T) {
var webhook codebuild.Webhook
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "aws_codebuild_webhook.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckAWSCodeBuild(t) },
ErrorCheck: testAccErrorCheck(t, codebuild.EndpointsID),
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSCodeBuildWebhookDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSCodeBuildWebhookConfig_BuildType(rName, "BUILD"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildWebhookExists(resourceName, &webhook),
resource.TestCheckResourceAttr(resourceName, "build_type", "BUILD"),
),
},
{
Config: testAccAWSCodeBuildWebhookConfig_BuildType(rName, "BUILD_BATCH"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildWebhookExists(resourceName, &webhook),
resource.TestCheckResourceAttr(resourceName, "build_type", "BUILD_BATCH"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"secret"},
},
},
})
}

func TestAccAWSCodeBuildWebhook_BranchFilter(t *testing.T) {
var webhook codebuild.Webhook
rName := acctest.RandomWithPrefix("tf-acc-test")
Expand Down Expand Up @@ -335,6 +370,15 @@ resource "aws_codebuild_webhook" "test" {
`, rName, branchFilter)
}

func testAccAWSCodeBuildWebhookConfig_BuildType(rName, branchFilter string) string {
return fmt.Sprintf(testAccAWSCodeBuildProjectConfig_basic(rName)+`
resource "aws_codebuild_webhook" "test" {
build_type = "%s"
project_name = aws_codebuild_project.test.name
}
`, branchFilter)
}

func testAccAWSCodeBuildWebhookConfig_BranchFilter(rName, branchFilter string) string {
return fmt.Sprintf(testAccAWSCodeBuildProjectConfig_basic(rName)+`
resource "aws_codebuild_webhook" "test" {
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/codebuild_webhook.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ When working with [Bitbucket](https://bitbucket.org) and [GitHub](https://github
```terraform
resource "aws_codebuild_webhook" "example" {
project_name = aws_codebuild_project.example.name

build_type = "BUILD"
filter_group {
filter {
type = "EVENT"
Expand Down Expand Up @@ -69,6 +69,7 @@ resource "github_repository_webhook" "example" {
The following arguments are supported:

* `project_name` - (Required) The name of the build project.
* `build_type` - (Optional) The type of build this webhook will trigger(BUILD | BUILD_BATCH).
* `branch_filter` - (Optional) A regular expression used to determine which branches get built. Default is all branches are built. It is recommended to use `filter_group` over `branch_filter`.
* `filter_group` - (Optional) Information about the webhook's trigger. Filter group blocks are documented below.

Expand Down