github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/waf/webAcl.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 waf
     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  // Provides a WAF Web ACL Resource
    16  //
    17  // ## Example Usage
    18  //
    19  // This example blocks requests coming from `192.0.7.0/24` and allows everything else.
    20  //
    21  // <!--Start PulumiCodeChooser -->
    22  // ```go
    23  // package main
    24  //
    25  // import (
    26  //
    27  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/waf"
    28  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    29  //
    30  // )
    31  //
    32  //	func main() {
    33  //		pulumi.Run(func(ctx *pulumi.Context) error {
    34  //			ipset, err := waf.NewIpSet(ctx, "ipset", &waf.IpSetArgs{
    35  //				Name: pulumi.String("tfIPSet"),
    36  //				IpSetDescriptors: waf.IpSetIpSetDescriptorArray{
    37  //					&waf.IpSetIpSetDescriptorArgs{
    38  //						Type:  pulumi.String("IPV4"),
    39  //						Value: pulumi.String("192.0.7.0/24"),
    40  //					},
    41  //				},
    42  //			})
    43  //			if err != nil {
    44  //				return err
    45  //			}
    46  //			wafrule, err := waf.NewRule(ctx, "wafrule", &waf.RuleArgs{
    47  //				Name:       pulumi.String("tfWAFRule"),
    48  //				MetricName: pulumi.String("tfWAFRule"),
    49  //				Predicates: waf.RulePredicateArray{
    50  //					&waf.RulePredicateArgs{
    51  //						DataId:  ipset.ID(),
    52  //						Negated: pulumi.Bool(false),
    53  //						Type:    pulumi.String("IPMatch"),
    54  //					},
    55  //				},
    56  //			}, pulumi.DependsOn([]pulumi.Resource{
    57  //				ipset,
    58  //			}))
    59  //			if err != nil {
    60  //				return err
    61  //			}
    62  //			_, err = waf.NewWebAcl(ctx, "waf_acl", &waf.WebAclArgs{
    63  //				Name:       pulumi.String("tfWebACL"),
    64  //				MetricName: pulumi.String("tfWebACL"),
    65  //				DefaultAction: &waf.WebAclDefaultActionArgs{
    66  //					Type: pulumi.String("ALLOW"),
    67  //				},
    68  //				Rules: waf.WebAclRuleArray{
    69  //					&waf.WebAclRuleArgs{
    70  //						Action: &waf.WebAclRuleActionArgs{
    71  //							Type: pulumi.String("BLOCK"),
    72  //						},
    73  //						Priority: pulumi.Int(1),
    74  //						RuleId:   wafrule.ID(),
    75  //						Type:     pulumi.String("REGULAR"),
    76  //					},
    77  //				},
    78  //			}, pulumi.DependsOn([]pulumi.Resource{
    79  //				ipset,
    80  //				wafrule,
    81  //			}))
    82  //			if err != nil {
    83  //				return err
    84  //			}
    85  //			return nil
    86  //		})
    87  //	}
    88  //
    89  // ```
    90  // <!--End PulumiCodeChooser -->
    91  //
    92  // ### Logging
    93  //
    94  // > *NOTE:* The Kinesis Firehose Delivery Stream name must begin with `aws-waf-logs-` and be located in `us-east-1` region. See the [AWS WAF Developer Guide](https://docs.aws.amazon.com/waf/latest/developerguide/logging.html) for more information about enabling WAF logging.
    95  //
    96  // <!--Start PulumiCodeChooser -->
    97  // ```go
    98  // package main
    99  //
   100  // import (
   101  //
   102  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/waf"
   103  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
   104  //
   105  // )
   106  //
   107  //	func main() {
   108  //		pulumi.Run(func(ctx *pulumi.Context) error {
   109  //			_, err := waf.NewWebAcl(ctx, "example", &waf.WebAclArgs{
   110  //				LoggingConfiguration: &waf.WebAclLoggingConfigurationArgs{
   111  //					LogDestination: pulumi.Any(exampleAwsKinesisFirehoseDeliveryStream.Arn),
   112  //					RedactedFields: &waf.WebAclLoggingConfigurationRedactedFieldsArgs{
   113  //						FieldToMatches: waf.WebAclLoggingConfigurationRedactedFieldsFieldToMatchArray{
   114  //							&waf.WebAclLoggingConfigurationRedactedFieldsFieldToMatchArgs{
   115  //								Type: pulumi.String("URI"),
   116  //							},
   117  //							&waf.WebAclLoggingConfigurationRedactedFieldsFieldToMatchArgs{
   118  //								Data: pulumi.String("referer"),
   119  //								Type: pulumi.String("HEADER"),
   120  //							},
   121  //						},
   122  //					},
   123  //				},
   124  //			})
   125  //			if err != nil {
   126  //				return err
   127  //			}
   128  //			return nil
   129  //		})
   130  //	}
   131  //
   132  // ```
   133  // <!--End PulumiCodeChooser -->
   134  //
   135  // ## Import
   136  //
   137  // Using `pulumi import`, import WAF Web ACL using the `id`. For example:
   138  //
   139  // ```sh
   140  // $ pulumi import aws:waf/webAcl:WebAcl main 0c8e583e-18f3-4c13-9e2a-67c4805d2f94
   141  // ```
   142  type WebAcl struct {
   143  	pulumi.CustomResourceState
   144  
   145  	// The ARN of the WAF WebACL.
   146  	Arn pulumi.StringOutput `pulumi:"arn"`
   147  	// Configuration block with action that you want AWS WAF to take when a request doesn't match the criteria in any of the rules that are associated with the web ACL. Detailed below.
   148  	DefaultAction WebAclDefaultActionOutput `pulumi:"defaultAction"`
   149  	// Configuration block to enable WAF logging. Detailed below.
   150  	LoggingConfiguration WebAclLoggingConfigurationPtrOutput `pulumi:"loggingConfiguration"`
   151  	// The name or description for the Amazon CloudWatch metric of this web ACL.
   152  	MetricName pulumi.StringOutput `pulumi:"metricName"`
   153  	// The name or description of the web ACL.
   154  	Name pulumi.StringOutput `pulumi:"name"`
   155  	// Configuration blocks containing rules to associate with the web ACL and the settings for each rule. Detailed below.
   156  	Rules WebAclRuleArrayOutput `pulumi:"rules"`
   157  	// Key-value map of resource tags. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   158  	Tags pulumi.StringMapOutput `pulumi:"tags"`
   159  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   160  	//
   161  	// Deprecated: Please use `tags` instead.
   162  	TagsAll pulumi.StringMapOutput `pulumi:"tagsAll"`
   163  }
   164  
   165  // NewWebAcl registers a new resource with the given unique name, arguments, and options.
   166  func NewWebAcl(ctx *pulumi.Context,
   167  	name string, args *WebAclArgs, opts ...pulumi.ResourceOption) (*WebAcl, error) {
   168  	if args == nil {
   169  		return nil, errors.New("missing one or more required arguments")
   170  	}
   171  
   172  	if args.DefaultAction == nil {
   173  		return nil, errors.New("invalid value for required argument 'DefaultAction'")
   174  	}
   175  	if args.MetricName == nil {
   176  		return nil, errors.New("invalid value for required argument 'MetricName'")
   177  	}
   178  	opts = internal.PkgResourceDefaultOpts(opts)
   179  	var resource WebAcl
   180  	err := ctx.RegisterResource("aws:waf/webAcl:WebAcl", name, args, &resource, opts...)
   181  	if err != nil {
   182  		return nil, err
   183  	}
   184  	return &resource, nil
   185  }
   186  
   187  // GetWebAcl gets an existing WebAcl resource's state with the given name, ID, and optional
   188  // state properties that are used to uniquely qualify the lookup (nil if not required).
   189  func GetWebAcl(ctx *pulumi.Context,
   190  	name string, id pulumi.IDInput, state *WebAclState, opts ...pulumi.ResourceOption) (*WebAcl, error) {
   191  	var resource WebAcl
   192  	err := ctx.ReadResource("aws:waf/webAcl:WebAcl", name, id, state, &resource, opts...)
   193  	if err != nil {
   194  		return nil, err
   195  	}
   196  	return &resource, nil
   197  }
   198  
   199  // Input properties used for looking up and filtering WebAcl resources.
   200  type webAclState struct {
   201  	// The ARN of the WAF WebACL.
   202  	Arn *string `pulumi:"arn"`
   203  	// Configuration block with action that you want AWS WAF to take when a request doesn't match the criteria in any of the rules that are associated with the web ACL. Detailed below.
   204  	DefaultAction *WebAclDefaultAction `pulumi:"defaultAction"`
   205  	// Configuration block to enable WAF logging. Detailed below.
   206  	LoggingConfiguration *WebAclLoggingConfiguration `pulumi:"loggingConfiguration"`
   207  	// The name or description for the Amazon CloudWatch metric of this web ACL.
   208  	MetricName *string `pulumi:"metricName"`
   209  	// The name or description of the web ACL.
   210  	Name *string `pulumi:"name"`
   211  	// Configuration blocks containing rules to associate with the web ACL and the settings for each rule. Detailed below.
   212  	Rules []WebAclRule `pulumi:"rules"`
   213  	// Key-value map of resource tags. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   214  	Tags map[string]string `pulumi:"tags"`
   215  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   216  	//
   217  	// Deprecated: Please use `tags` instead.
   218  	TagsAll map[string]string `pulumi:"tagsAll"`
   219  }
   220  
   221  type WebAclState struct {
   222  	// The ARN of the WAF WebACL.
   223  	Arn pulumi.StringPtrInput
   224  	// Configuration block with action that you want AWS WAF to take when a request doesn't match the criteria in any of the rules that are associated with the web ACL. Detailed below.
   225  	DefaultAction WebAclDefaultActionPtrInput
   226  	// Configuration block to enable WAF logging. Detailed below.
   227  	LoggingConfiguration WebAclLoggingConfigurationPtrInput
   228  	// The name or description for the Amazon CloudWatch metric of this web ACL.
   229  	MetricName pulumi.StringPtrInput
   230  	// The name or description of the web ACL.
   231  	Name pulumi.StringPtrInput
   232  	// Configuration blocks containing rules to associate with the web ACL and the settings for each rule. Detailed below.
   233  	Rules WebAclRuleArrayInput
   234  	// Key-value map of resource tags. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   235  	Tags pulumi.StringMapInput
   236  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   237  	//
   238  	// Deprecated: Please use `tags` instead.
   239  	TagsAll pulumi.StringMapInput
   240  }
   241  
   242  func (WebAclState) ElementType() reflect.Type {
   243  	return reflect.TypeOf((*webAclState)(nil)).Elem()
   244  }
   245  
   246  type webAclArgs struct {
   247  	// Configuration block with action that you want AWS WAF to take when a request doesn't match the criteria in any of the rules that are associated with the web ACL. Detailed below.
   248  	DefaultAction WebAclDefaultAction `pulumi:"defaultAction"`
   249  	// Configuration block to enable WAF logging. Detailed below.
   250  	LoggingConfiguration *WebAclLoggingConfiguration `pulumi:"loggingConfiguration"`
   251  	// The name or description for the Amazon CloudWatch metric of this web ACL.
   252  	MetricName string `pulumi:"metricName"`
   253  	// The name or description of the web ACL.
   254  	Name *string `pulumi:"name"`
   255  	// Configuration blocks containing rules to associate with the web ACL and the settings for each rule. Detailed below.
   256  	Rules []WebAclRule `pulumi:"rules"`
   257  	// Key-value map of resource tags. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   258  	Tags map[string]string `pulumi:"tags"`
   259  }
   260  
   261  // The set of arguments for constructing a WebAcl resource.
   262  type WebAclArgs struct {
   263  	// Configuration block with action that you want AWS WAF to take when a request doesn't match the criteria in any of the rules that are associated with the web ACL. Detailed below.
   264  	DefaultAction WebAclDefaultActionInput
   265  	// Configuration block to enable WAF logging. Detailed below.
   266  	LoggingConfiguration WebAclLoggingConfigurationPtrInput
   267  	// The name or description for the Amazon CloudWatch metric of this web ACL.
   268  	MetricName pulumi.StringInput
   269  	// The name or description of the web ACL.
   270  	Name pulumi.StringPtrInput
   271  	// Configuration blocks containing rules to associate with the web ACL and the settings for each rule. Detailed below.
   272  	Rules WebAclRuleArrayInput
   273  	// Key-value map of resource tags. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   274  	Tags pulumi.StringMapInput
   275  }
   276  
   277  func (WebAclArgs) ElementType() reflect.Type {
   278  	return reflect.TypeOf((*webAclArgs)(nil)).Elem()
   279  }
   280  
   281  type WebAclInput interface {
   282  	pulumi.Input
   283  
   284  	ToWebAclOutput() WebAclOutput
   285  	ToWebAclOutputWithContext(ctx context.Context) WebAclOutput
   286  }
   287  
   288  func (*WebAcl) ElementType() reflect.Type {
   289  	return reflect.TypeOf((**WebAcl)(nil)).Elem()
   290  }
   291  
   292  func (i *WebAcl) ToWebAclOutput() WebAclOutput {
   293  	return i.ToWebAclOutputWithContext(context.Background())
   294  }
   295  
   296  func (i *WebAcl) ToWebAclOutputWithContext(ctx context.Context) WebAclOutput {
   297  	return pulumi.ToOutputWithContext(ctx, i).(WebAclOutput)
   298  }
   299  
   300  // WebAclArrayInput is an input type that accepts WebAclArray and WebAclArrayOutput values.
   301  // You can construct a concrete instance of `WebAclArrayInput` via:
   302  //
   303  //	WebAclArray{ WebAclArgs{...} }
   304  type WebAclArrayInput interface {
   305  	pulumi.Input
   306  
   307  	ToWebAclArrayOutput() WebAclArrayOutput
   308  	ToWebAclArrayOutputWithContext(context.Context) WebAclArrayOutput
   309  }
   310  
   311  type WebAclArray []WebAclInput
   312  
   313  func (WebAclArray) ElementType() reflect.Type {
   314  	return reflect.TypeOf((*[]*WebAcl)(nil)).Elem()
   315  }
   316  
   317  func (i WebAclArray) ToWebAclArrayOutput() WebAclArrayOutput {
   318  	return i.ToWebAclArrayOutputWithContext(context.Background())
   319  }
   320  
   321  func (i WebAclArray) ToWebAclArrayOutputWithContext(ctx context.Context) WebAclArrayOutput {
   322  	return pulumi.ToOutputWithContext(ctx, i).(WebAclArrayOutput)
   323  }
   324  
   325  // WebAclMapInput is an input type that accepts WebAclMap and WebAclMapOutput values.
   326  // You can construct a concrete instance of `WebAclMapInput` via:
   327  //
   328  //	WebAclMap{ "key": WebAclArgs{...} }
   329  type WebAclMapInput interface {
   330  	pulumi.Input
   331  
   332  	ToWebAclMapOutput() WebAclMapOutput
   333  	ToWebAclMapOutputWithContext(context.Context) WebAclMapOutput
   334  }
   335  
   336  type WebAclMap map[string]WebAclInput
   337  
   338  func (WebAclMap) ElementType() reflect.Type {
   339  	return reflect.TypeOf((*map[string]*WebAcl)(nil)).Elem()
   340  }
   341  
   342  func (i WebAclMap) ToWebAclMapOutput() WebAclMapOutput {
   343  	return i.ToWebAclMapOutputWithContext(context.Background())
   344  }
   345  
   346  func (i WebAclMap) ToWebAclMapOutputWithContext(ctx context.Context) WebAclMapOutput {
   347  	return pulumi.ToOutputWithContext(ctx, i).(WebAclMapOutput)
   348  }
   349  
   350  type WebAclOutput struct{ *pulumi.OutputState }
   351  
   352  func (WebAclOutput) ElementType() reflect.Type {
   353  	return reflect.TypeOf((**WebAcl)(nil)).Elem()
   354  }
   355  
   356  func (o WebAclOutput) ToWebAclOutput() WebAclOutput {
   357  	return o
   358  }
   359  
   360  func (o WebAclOutput) ToWebAclOutputWithContext(ctx context.Context) WebAclOutput {
   361  	return o
   362  }
   363  
   364  // The ARN of the WAF WebACL.
   365  func (o WebAclOutput) Arn() pulumi.StringOutput {
   366  	return o.ApplyT(func(v *WebAcl) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput)
   367  }
   368  
   369  // Configuration block with action that you want AWS WAF to take when a request doesn't match the criteria in any of the rules that are associated with the web ACL. Detailed below.
   370  func (o WebAclOutput) DefaultAction() WebAclDefaultActionOutput {
   371  	return o.ApplyT(func(v *WebAcl) WebAclDefaultActionOutput { return v.DefaultAction }).(WebAclDefaultActionOutput)
   372  }
   373  
   374  // Configuration block to enable WAF logging. Detailed below.
   375  func (o WebAclOutput) LoggingConfiguration() WebAclLoggingConfigurationPtrOutput {
   376  	return o.ApplyT(func(v *WebAcl) WebAclLoggingConfigurationPtrOutput { return v.LoggingConfiguration }).(WebAclLoggingConfigurationPtrOutput)
   377  }
   378  
   379  // The name or description for the Amazon CloudWatch metric of this web ACL.
   380  func (o WebAclOutput) MetricName() pulumi.StringOutput {
   381  	return o.ApplyT(func(v *WebAcl) pulumi.StringOutput { return v.MetricName }).(pulumi.StringOutput)
   382  }
   383  
   384  // The name or description of the web ACL.
   385  func (o WebAclOutput) Name() pulumi.StringOutput {
   386  	return o.ApplyT(func(v *WebAcl) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
   387  }
   388  
   389  // Configuration blocks containing rules to associate with the web ACL and the settings for each rule. Detailed below.
   390  func (o WebAclOutput) Rules() WebAclRuleArrayOutput {
   391  	return o.ApplyT(func(v *WebAcl) WebAclRuleArrayOutput { return v.Rules }).(WebAclRuleArrayOutput)
   392  }
   393  
   394  // Key-value map of resource tags. .If configured with a provider `defaultTags` configuration block present, tags with matching keys will overwrite those defined at the provider-level.
   395  func (o WebAclOutput) Tags() pulumi.StringMapOutput {
   396  	return o.ApplyT(func(v *WebAcl) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput)
   397  }
   398  
   399  // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   400  //
   401  // Deprecated: Please use `tags` instead.
   402  func (o WebAclOutput) TagsAll() pulumi.StringMapOutput {
   403  	return o.ApplyT(func(v *WebAcl) pulumi.StringMapOutput { return v.TagsAll }).(pulumi.StringMapOutput)
   404  }
   405  
   406  type WebAclArrayOutput struct{ *pulumi.OutputState }
   407  
   408  func (WebAclArrayOutput) ElementType() reflect.Type {
   409  	return reflect.TypeOf((*[]*WebAcl)(nil)).Elem()
   410  }
   411  
   412  func (o WebAclArrayOutput) ToWebAclArrayOutput() WebAclArrayOutput {
   413  	return o
   414  }
   415  
   416  func (o WebAclArrayOutput) ToWebAclArrayOutputWithContext(ctx context.Context) WebAclArrayOutput {
   417  	return o
   418  }
   419  
   420  func (o WebAclArrayOutput) Index(i pulumi.IntInput) WebAclOutput {
   421  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *WebAcl {
   422  		return vs[0].([]*WebAcl)[vs[1].(int)]
   423  	}).(WebAclOutput)
   424  }
   425  
   426  type WebAclMapOutput struct{ *pulumi.OutputState }
   427  
   428  func (WebAclMapOutput) ElementType() reflect.Type {
   429  	return reflect.TypeOf((*map[string]*WebAcl)(nil)).Elem()
   430  }
   431  
   432  func (o WebAclMapOutput) ToWebAclMapOutput() WebAclMapOutput {
   433  	return o
   434  }
   435  
   436  func (o WebAclMapOutput) ToWebAclMapOutputWithContext(ctx context.Context) WebAclMapOutput {
   437  	return o
   438  }
   439  
   440  func (o WebAclMapOutput) MapIndex(k pulumi.StringInput) WebAclOutput {
   441  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *WebAcl {
   442  		return vs[0].(map[string]*WebAcl)[vs[1].(string)]
   443  	}).(WebAclOutput)
   444  }
   445  
   446  func init() {
   447  	pulumi.RegisterInputType(reflect.TypeOf((*WebAclInput)(nil)).Elem(), &WebAcl{})
   448  	pulumi.RegisterInputType(reflect.TypeOf((*WebAclArrayInput)(nil)).Elem(), WebAclArray{})
   449  	pulumi.RegisterInputType(reflect.TypeOf((*WebAclMapInput)(nil)).Elem(), WebAclMap{})
   450  	pulumi.RegisterOutputType(WebAclOutput{})
   451  	pulumi.RegisterOutputType(WebAclArrayOutput{})
   452  	pulumi.RegisterOutputType(WebAclMapOutput{})
   453  }