github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/codebuild/webhook.go (about)

     1  // Code generated by the Pulumi Terraform Bridge (tfgen) Tool DO NOT EDIT.
     2  // *** WARNING: Do not edit by hand unless you're certain you know what you are doing! ***
     3  
     4  package codebuild
     5  
     6  import (
     7  	"context"
     8  	"reflect"
     9  
    10  	"errors"
    11  	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/internal"
    12  	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    13  )
    14  
    15  // 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.
    16  //
    17  // ## Example Usage
    18  //
    19  // ### Bitbucket and GitHub
    20  //
    21  // When working with [Bitbucket](https://bitbucket.org) and [GitHub](https://github.com) source CodeBuild webhooks, the CodeBuild service will automatically create (on `codebuild.Webhook` resource creation) and delete (on `codebuild.Webhook` resource deletion) the Bitbucket/GitHub repository webhook using its granted OAuth permissions. This behavior cannot be controlled by this provider.
    22  //
    23  // > **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](https://docs.aws.amazon.com/codebuild/latest/userguide/sample-bitbucket-pull-request.html) and [GitHub](https://docs.aws.amazon.com/codebuild/latest/userguide/sample-github-pull-request.html).
    24  //
    25  // > **Note:** Further managing the automatically created Bitbucket/GitHub webhook with the `bitbucketHook`/`githubRepositoryWebhook` resource is only possible with importing that resource after creation of the `codebuild.Webhook` resource. The CodeBuild API does not ever provide the `secret` attribute for the `codebuild.Webhook` resource in this scenario.
    26  //
    27  // <!--Start PulumiCodeChooser -->
    28  // ```go
    29  // package main
    30  //
    31  // import (
    32  //
    33  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/codebuild"
    34  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    35  //
    36  // )
    37  //
    38  //	func main() {
    39  //		pulumi.Run(func(ctx *pulumi.Context) error {
    40  //			_, err := codebuild.NewWebhook(ctx, "example", &codebuild.WebhookArgs{
    41  //				ProjectName: pulumi.Any(exampleAwsCodebuildProject.Name),
    42  //				BuildType:   pulumi.String("BUILD"),
    43  //				FilterGroups: codebuild.WebhookFilterGroupArray{
    44  //					&codebuild.WebhookFilterGroupArgs{
    45  //						Filters: codebuild.WebhookFilterGroupFilterArray{
    46  //							&codebuild.WebhookFilterGroupFilterArgs{
    47  //								Type:    pulumi.String("EVENT"),
    48  //								Pattern: pulumi.String("PUSH"),
    49  //							},
    50  //							&codebuild.WebhookFilterGroupFilterArgs{
    51  //								Type:    pulumi.String("BASE_REF"),
    52  //								Pattern: pulumi.String("master"),
    53  //							},
    54  //						},
    55  //					},
    56  //				},
    57  //			})
    58  //			if err != nil {
    59  //				return err
    60  //			}
    61  //			return nil
    62  //		})
    63  //	}
    64  //
    65  // ```
    66  // <!--End PulumiCodeChooser -->
    67  //
    68  // ## Import
    69  //
    70  // Using `pulumi import`, import CodeBuild Webhooks using the CodeBuild Project name. For example:
    71  //
    72  // ```sh
    73  // $ pulumi import aws:codebuild/webhook:Webhook example MyProjectName
    74  // ```
    75  type Webhook struct {
    76  	pulumi.CustomResourceState
    77  
    78  	// A regular expression used to determine which branches get built. Default is all branches are built. We recommend using `filterGroup` over `branchFilter`.
    79  	BranchFilter pulumi.StringPtrOutput `pulumi:"branchFilter"`
    80  	// The type of build this webhook will trigger. Valid values for this parameter are: `BUILD`, `BUILD_BATCH`.
    81  	BuildType pulumi.StringPtrOutput `pulumi:"buildType"`
    82  	// Information about the webhook's trigger. Filter group blocks are documented below.
    83  	FilterGroups WebhookFilterGroupArrayOutput `pulumi:"filterGroups"`
    84  	// The CodeBuild endpoint where webhook events are sent.
    85  	PayloadUrl pulumi.StringOutput `pulumi:"payloadUrl"`
    86  	// The name of the build project.
    87  	ProjectName pulumi.StringOutput `pulumi:"projectName"`
    88  	// The secret token of the associated repository. Not returned by the CodeBuild API for all source types.
    89  	Secret pulumi.StringOutput `pulumi:"secret"`
    90  	// The URL to the webhook.
    91  	Url pulumi.StringOutput `pulumi:"url"`
    92  }
    93  
    94  // NewWebhook registers a new resource with the given unique name, arguments, and options.
    95  func NewWebhook(ctx *pulumi.Context,
    96  	name string, args *WebhookArgs, opts ...pulumi.ResourceOption) (*Webhook, error) {
    97  	if args == nil {
    98  		return nil, errors.New("missing one or more required arguments")
    99  	}
   100  
   101  	if args.ProjectName == nil {
   102  		return nil, errors.New("invalid value for required argument 'ProjectName'")
   103  	}
   104  	secrets := pulumi.AdditionalSecretOutputs([]string{
   105  		"secret",
   106  	})
   107  	opts = append(opts, secrets)
   108  	opts = internal.PkgResourceDefaultOpts(opts)
   109  	var resource Webhook
   110  	err := ctx.RegisterResource("aws:codebuild/webhook:Webhook", name, args, &resource, opts...)
   111  	if err != nil {
   112  		return nil, err
   113  	}
   114  	return &resource, nil
   115  }
   116  
   117  // GetWebhook gets an existing Webhook resource's state with the given name, ID, and optional
   118  // state properties that are used to uniquely qualify the lookup (nil if not required).
   119  func GetWebhook(ctx *pulumi.Context,
   120  	name string, id pulumi.IDInput, state *WebhookState, opts ...pulumi.ResourceOption) (*Webhook, error) {
   121  	var resource Webhook
   122  	err := ctx.ReadResource("aws:codebuild/webhook:Webhook", name, id, state, &resource, opts...)
   123  	if err != nil {
   124  		return nil, err
   125  	}
   126  	return &resource, nil
   127  }
   128  
   129  // Input properties used for looking up and filtering Webhook resources.
   130  type webhookState struct {
   131  	// A regular expression used to determine which branches get built. Default is all branches are built. We recommend using `filterGroup` over `branchFilter`.
   132  	BranchFilter *string `pulumi:"branchFilter"`
   133  	// The type of build this webhook will trigger. Valid values for this parameter are: `BUILD`, `BUILD_BATCH`.
   134  	BuildType *string `pulumi:"buildType"`
   135  	// Information about the webhook's trigger. Filter group blocks are documented below.
   136  	FilterGroups []WebhookFilterGroup `pulumi:"filterGroups"`
   137  	// The CodeBuild endpoint where webhook events are sent.
   138  	PayloadUrl *string `pulumi:"payloadUrl"`
   139  	// The name of the build project.
   140  	ProjectName *string `pulumi:"projectName"`
   141  	// The secret token of the associated repository. Not returned by the CodeBuild API for all source types.
   142  	Secret *string `pulumi:"secret"`
   143  	// The URL to the webhook.
   144  	Url *string `pulumi:"url"`
   145  }
   146  
   147  type WebhookState struct {
   148  	// A regular expression used to determine which branches get built. Default is all branches are built. We recommend using `filterGroup` over `branchFilter`.
   149  	BranchFilter pulumi.StringPtrInput
   150  	// The type of build this webhook will trigger. Valid values for this parameter are: `BUILD`, `BUILD_BATCH`.
   151  	BuildType pulumi.StringPtrInput
   152  	// Information about the webhook's trigger. Filter group blocks are documented below.
   153  	FilterGroups WebhookFilterGroupArrayInput
   154  	// The CodeBuild endpoint where webhook events are sent.
   155  	PayloadUrl pulumi.StringPtrInput
   156  	// The name of the build project.
   157  	ProjectName pulumi.StringPtrInput
   158  	// The secret token of the associated repository. Not returned by the CodeBuild API for all source types.
   159  	Secret pulumi.StringPtrInput
   160  	// The URL to the webhook.
   161  	Url pulumi.StringPtrInput
   162  }
   163  
   164  func (WebhookState) ElementType() reflect.Type {
   165  	return reflect.TypeOf((*webhookState)(nil)).Elem()
   166  }
   167  
   168  type webhookArgs struct {
   169  	// A regular expression used to determine which branches get built. Default is all branches are built. We recommend using `filterGroup` over `branchFilter`.
   170  	BranchFilter *string `pulumi:"branchFilter"`
   171  	// The type of build this webhook will trigger. Valid values for this parameter are: `BUILD`, `BUILD_BATCH`.
   172  	BuildType *string `pulumi:"buildType"`
   173  	// Information about the webhook's trigger. Filter group blocks are documented below.
   174  	FilterGroups []WebhookFilterGroup `pulumi:"filterGroups"`
   175  	// The name of the build project.
   176  	ProjectName string `pulumi:"projectName"`
   177  }
   178  
   179  // The set of arguments for constructing a Webhook resource.
   180  type WebhookArgs struct {
   181  	// A regular expression used to determine which branches get built. Default is all branches are built. We recommend using `filterGroup` over `branchFilter`.
   182  	BranchFilter pulumi.StringPtrInput
   183  	// The type of build this webhook will trigger. Valid values for this parameter are: `BUILD`, `BUILD_BATCH`.
   184  	BuildType pulumi.StringPtrInput
   185  	// Information about the webhook's trigger. Filter group blocks are documented below.
   186  	FilterGroups WebhookFilterGroupArrayInput
   187  	// The name of the build project.
   188  	ProjectName pulumi.StringInput
   189  }
   190  
   191  func (WebhookArgs) ElementType() reflect.Type {
   192  	return reflect.TypeOf((*webhookArgs)(nil)).Elem()
   193  }
   194  
   195  type WebhookInput interface {
   196  	pulumi.Input
   197  
   198  	ToWebhookOutput() WebhookOutput
   199  	ToWebhookOutputWithContext(ctx context.Context) WebhookOutput
   200  }
   201  
   202  func (*Webhook) ElementType() reflect.Type {
   203  	return reflect.TypeOf((**Webhook)(nil)).Elem()
   204  }
   205  
   206  func (i *Webhook) ToWebhookOutput() WebhookOutput {
   207  	return i.ToWebhookOutputWithContext(context.Background())
   208  }
   209  
   210  func (i *Webhook) ToWebhookOutputWithContext(ctx context.Context) WebhookOutput {
   211  	return pulumi.ToOutputWithContext(ctx, i).(WebhookOutput)
   212  }
   213  
   214  // WebhookArrayInput is an input type that accepts WebhookArray and WebhookArrayOutput values.
   215  // You can construct a concrete instance of `WebhookArrayInput` via:
   216  //
   217  //	WebhookArray{ WebhookArgs{...} }
   218  type WebhookArrayInput interface {
   219  	pulumi.Input
   220  
   221  	ToWebhookArrayOutput() WebhookArrayOutput
   222  	ToWebhookArrayOutputWithContext(context.Context) WebhookArrayOutput
   223  }
   224  
   225  type WebhookArray []WebhookInput
   226  
   227  func (WebhookArray) ElementType() reflect.Type {
   228  	return reflect.TypeOf((*[]*Webhook)(nil)).Elem()
   229  }
   230  
   231  func (i WebhookArray) ToWebhookArrayOutput() WebhookArrayOutput {
   232  	return i.ToWebhookArrayOutputWithContext(context.Background())
   233  }
   234  
   235  func (i WebhookArray) ToWebhookArrayOutputWithContext(ctx context.Context) WebhookArrayOutput {
   236  	return pulumi.ToOutputWithContext(ctx, i).(WebhookArrayOutput)
   237  }
   238  
   239  // WebhookMapInput is an input type that accepts WebhookMap and WebhookMapOutput values.
   240  // You can construct a concrete instance of `WebhookMapInput` via:
   241  //
   242  //	WebhookMap{ "key": WebhookArgs{...} }
   243  type WebhookMapInput interface {
   244  	pulumi.Input
   245  
   246  	ToWebhookMapOutput() WebhookMapOutput
   247  	ToWebhookMapOutputWithContext(context.Context) WebhookMapOutput
   248  }
   249  
   250  type WebhookMap map[string]WebhookInput
   251  
   252  func (WebhookMap) ElementType() reflect.Type {
   253  	return reflect.TypeOf((*map[string]*Webhook)(nil)).Elem()
   254  }
   255  
   256  func (i WebhookMap) ToWebhookMapOutput() WebhookMapOutput {
   257  	return i.ToWebhookMapOutputWithContext(context.Background())
   258  }
   259  
   260  func (i WebhookMap) ToWebhookMapOutputWithContext(ctx context.Context) WebhookMapOutput {
   261  	return pulumi.ToOutputWithContext(ctx, i).(WebhookMapOutput)
   262  }
   263  
   264  type WebhookOutput struct{ *pulumi.OutputState }
   265  
   266  func (WebhookOutput) ElementType() reflect.Type {
   267  	return reflect.TypeOf((**Webhook)(nil)).Elem()
   268  }
   269  
   270  func (o WebhookOutput) ToWebhookOutput() WebhookOutput {
   271  	return o
   272  }
   273  
   274  func (o WebhookOutput) ToWebhookOutputWithContext(ctx context.Context) WebhookOutput {
   275  	return o
   276  }
   277  
   278  // A regular expression used to determine which branches get built. Default is all branches are built. We recommend using `filterGroup` over `branchFilter`.
   279  func (o WebhookOutput) BranchFilter() pulumi.StringPtrOutput {
   280  	return o.ApplyT(func(v *Webhook) pulumi.StringPtrOutput { return v.BranchFilter }).(pulumi.StringPtrOutput)
   281  }
   282  
   283  // The type of build this webhook will trigger. Valid values for this parameter are: `BUILD`, `BUILD_BATCH`.
   284  func (o WebhookOutput) BuildType() pulumi.StringPtrOutput {
   285  	return o.ApplyT(func(v *Webhook) pulumi.StringPtrOutput { return v.BuildType }).(pulumi.StringPtrOutput)
   286  }
   287  
   288  // Information about the webhook's trigger. Filter group blocks are documented below.
   289  func (o WebhookOutput) FilterGroups() WebhookFilterGroupArrayOutput {
   290  	return o.ApplyT(func(v *Webhook) WebhookFilterGroupArrayOutput { return v.FilterGroups }).(WebhookFilterGroupArrayOutput)
   291  }
   292  
   293  // The CodeBuild endpoint where webhook events are sent.
   294  func (o WebhookOutput) PayloadUrl() pulumi.StringOutput {
   295  	return o.ApplyT(func(v *Webhook) pulumi.StringOutput { return v.PayloadUrl }).(pulumi.StringOutput)
   296  }
   297  
   298  // The name of the build project.
   299  func (o WebhookOutput) ProjectName() pulumi.StringOutput {
   300  	return o.ApplyT(func(v *Webhook) pulumi.StringOutput { return v.ProjectName }).(pulumi.StringOutput)
   301  }
   302  
   303  // The secret token of the associated repository. Not returned by the CodeBuild API for all source types.
   304  func (o WebhookOutput) Secret() pulumi.StringOutput {
   305  	return o.ApplyT(func(v *Webhook) pulumi.StringOutput { return v.Secret }).(pulumi.StringOutput)
   306  }
   307  
   308  // The URL to the webhook.
   309  func (o WebhookOutput) Url() pulumi.StringOutput {
   310  	return o.ApplyT(func(v *Webhook) pulumi.StringOutput { return v.Url }).(pulumi.StringOutput)
   311  }
   312  
   313  type WebhookArrayOutput struct{ *pulumi.OutputState }
   314  
   315  func (WebhookArrayOutput) ElementType() reflect.Type {
   316  	return reflect.TypeOf((*[]*Webhook)(nil)).Elem()
   317  }
   318  
   319  func (o WebhookArrayOutput) ToWebhookArrayOutput() WebhookArrayOutput {
   320  	return o
   321  }
   322  
   323  func (o WebhookArrayOutput) ToWebhookArrayOutputWithContext(ctx context.Context) WebhookArrayOutput {
   324  	return o
   325  }
   326  
   327  func (o WebhookArrayOutput) Index(i pulumi.IntInput) WebhookOutput {
   328  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Webhook {
   329  		return vs[0].([]*Webhook)[vs[1].(int)]
   330  	}).(WebhookOutput)
   331  }
   332  
   333  type WebhookMapOutput struct{ *pulumi.OutputState }
   334  
   335  func (WebhookMapOutput) ElementType() reflect.Type {
   336  	return reflect.TypeOf((*map[string]*Webhook)(nil)).Elem()
   337  }
   338  
   339  func (o WebhookMapOutput) ToWebhookMapOutput() WebhookMapOutput {
   340  	return o
   341  }
   342  
   343  func (o WebhookMapOutput) ToWebhookMapOutputWithContext(ctx context.Context) WebhookMapOutput {
   344  	return o
   345  }
   346  
   347  func (o WebhookMapOutput) MapIndex(k pulumi.StringInput) WebhookOutput {
   348  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Webhook {
   349  		return vs[0].(map[string]*Webhook)[vs[1].(string)]
   350  	}).(WebhookOutput)
   351  }
   352  
   353  func init() {
   354  	pulumi.RegisterInputType(reflect.TypeOf((*WebhookInput)(nil)).Elem(), &Webhook{})
   355  	pulumi.RegisterInputType(reflect.TypeOf((*WebhookArrayInput)(nil)).Elem(), WebhookArray{})
   356  	pulumi.RegisterInputType(reflect.TypeOf((*WebhookMapInput)(nil)).Elem(), WebhookMap{})
   357  	pulumi.RegisterOutputType(WebhookOutput{})
   358  	pulumi.RegisterOutputType(WebhookArrayOutput{})
   359  	pulumi.RegisterOutputType(WebhookMapOutput{})
   360  }