hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

[Enhancement]: Add REPOSITORY_NAME event type filter to aws_codebuild_webhook resource #38868

Open markmullme opened 4 weeks ago

markmullme commented 4 weeks ago

Description

CodeBuild has added a new filter type, REPOSITORY_NAME, to AWS Codebuild webhooks as described here: https://docs.aws.amazon.com/codebuild/latest/userguide/github-global-organization-webhook.html

and in the SDK here: https://github.com/aws/aws-sdk-go-v2/blob/main/service/codebuild/types/types.go#L2638

It works with GitHub global or organization webhooks only and allows Codebuild to filter webhook triggers when the repository name matches a regex.

Unfortunately, using REPOSITORY_NAME results in an error:

Error: expected type to be one of ["EVENT" "BASE_REF" "HEAD_REF" "ACTOR_ACCOUNT_ID" "FILE_PATH" "COMMIT_MESSAGE" "WORKFLOW_NAME" "TAG_NAME" "RELEASE_NAME"], got REPOSITORY_NAME

but if the resource is created manually it works and can be imported into state but including REPOSITORY_NAME as shown above will result in this error.

As a workaround I'm considering using a lifecycle such as:

  lifecycle {
    ignore_changes = [
      filter_group,  # TODO: Remove if REPOSITORY_NAME type is supported
    ]
  }

or just using repository webhooks instead of organization webhooks.

Unlike PR #38060 which added support for the WORKFLOW_JOB_QUEUED event pattern, supporting REPOSITORY_NAME requires a new event type which is only available with global/organization webhooks.

Maybe REPOSITORY_NAME would need to be added to the SDK enums here: https://github.com/aws/aws-sdk-go-v2/blob/main/service/codebuild/types/enums.go

such that WebhookFilterType would actually return REPOSITORY_NAME as a valid type? The SDK repo had a similar issue and gave a response that seems to indicate nothing can be done to fix it in the SDK: https://github.com/aws/aws-sdk-go-v2/issues/2620#issuecomment-2083246521 since the SDK is directly code generated from the API.

Maybe the terraform provider can overcome this instead?

Affected Resource(s) and/or Data Source(s)

Potential Terraform Configuration

resource "aws_codebuild_webhook" "this" {
  project_name = aws_codebuild_project.this.name
  build_type   = "BUILD"

  filter_group {
    filter {
      pattern = "my-repo-name"
      type    = "REPOSITORY_NAME"
    }
  }
}

References

Would you like to implement a fix?

None

github-actions[bot] commented 4 weeks ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

aristosvo commented 4 weeks ago

This issue seems to cover that. As soon as it is released as part of the SDK it will reach the Terraform Provider for AWS in the next SDK update (which is quit often!).