github.com/pulumi/pulumi-aws/sdk/v6@v6.32.0/go/aws/waf/rule.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 Rule Resource
    16  //
    17  // ## Example Usage
    18  //
    19  // <!--Start PulumiCodeChooser -->
    20  // ```go
    21  // package main
    22  //
    23  // import (
    24  //
    25  //	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/waf"
    26  //	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    27  //
    28  // )
    29  //
    30  //	func main() {
    31  //		pulumi.Run(func(ctx *pulumi.Context) error {
    32  //			ipset, err := waf.NewIpSet(ctx, "ipset", &waf.IpSetArgs{
    33  //				Name: pulumi.String("tfIPSet"),
    34  //				IpSetDescriptors: waf.IpSetIpSetDescriptorArray{
    35  //					&waf.IpSetIpSetDescriptorArgs{
    36  //						Type:  pulumi.String("IPV4"),
    37  //						Value: pulumi.String("192.0.7.0/24"),
    38  //					},
    39  //				},
    40  //			})
    41  //			if err != nil {
    42  //				return err
    43  //			}
    44  //			_, err = waf.NewRule(ctx, "wafrule", &waf.RuleArgs{
    45  //				Name:       pulumi.String("tfWAFRule"),
    46  //				MetricName: pulumi.String("tfWAFRule"),
    47  //				Predicates: waf.RulePredicateArray{
    48  //					&waf.RulePredicateArgs{
    49  //						DataId:  ipset.ID(),
    50  //						Negated: pulumi.Bool(false),
    51  //						Type:    pulumi.String("IPMatch"),
    52  //					},
    53  //				},
    54  //			}, pulumi.DependsOn([]pulumi.Resource{
    55  //				ipset,
    56  //			}))
    57  //			if err != nil {
    58  //				return err
    59  //			}
    60  //			return nil
    61  //		})
    62  //	}
    63  //
    64  // ```
    65  // <!--End PulumiCodeChooser -->
    66  //
    67  // ## Import
    68  //
    69  // Using `pulumi import`, import WAF rules using the id. For example:
    70  //
    71  // ```sh
    72  // $ pulumi import aws:waf/rule:Rule example a1b2c3d4-d5f6-7777-8888-9999aaaabbbbcccc
    73  // ```
    74  type Rule struct {
    75  	pulumi.CustomResourceState
    76  
    77  	// The ARN of the WAF rule.
    78  	Arn pulumi.StringOutput `pulumi:"arn"`
    79  	// The name or description for the Amazon CloudWatch metric of this rule. The name can contain only alphanumeric characters (A-Z, a-z, 0-9); the name can't contain whitespace.
    80  	MetricName pulumi.StringOutput `pulumi:"metricName"`
    81  	// The name or description of the rule.
    82  	Name pulumi.StringOutput `pulumi:"name"`
    83  	// The objects to include in a rule (documented below).
    84  	Predicates RulePredicateArrayOutput `pulumi:"predicates"`
    85  	// 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.
    86  	Tags pulumi.StringMapOutput `pulumi:"tags"`
    87  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
    88  	//
    89  	// Deprecated: Please use `tags` instead.
    90  	TagsAll pulumi.StringMapOutput `pulumi:"tagsAll"`
    91  }
    92  
    93  // NewRule registers a new resource with the given unique name, arguments, and options.
    94  func NewRule(ctx *pulumi.Context,
    95  	name string, args *RuleArgs, opts ...pulumi.ResourceOption) (*Rule, error) {
    96  	if args == nil {
    97  		return nil, errors.New("missing one or more required arguments")
    98  	}
    99  
   100  	if args.MetricName == nil {
   101  		return nil, errors.New("invalid value for required argument 'MetricName'")
   102  	}
   103  	opts = internal.PkgResourceDefaultOpts(opts)
   104  	var resource Rule
   105  	err := ctx.RegisterResource("aws:waf/rule:Rule", name, args, &resource, opts...)
   106  	if err != nil {
   107  		return nil, err
   108  	}
   109  	return &resource, nil
   110  }
   111  
   112  // GetRule gets an existing Rule resource's state with the given name, ID, and optional
   113  // state properties that are used to uniquely qualify the lookup (nil if not required).
   114  func GetRule(ctx *pulumi.Context,
   115  	name string, id pulumi.IDInput, state *RuleState, opts ...pulumi.ResourceOption) (*Rule, error) {
   116  	var resource Rule
   117  	err := ctx.ReadResource("aws:waf/rule:Rule", name, id, state, &resource, opts...)
   118  	if err != nil {
   119  		return nil, err
   120  	}
   121  	return &resource, nil
   122  }
   123  
   124  // Input properties used for looking up and filtering Rule resources.
   125  type ruleState struct {
   126  	// The ARN of the WAF rule.
   127  	Arn *string `pulumi:"arn"`
   128  	// The name or description for the Amazon CloudWatch metric of this rule. The name can contain only alphanumeric characters (A-Z, a-z, 0-9); the name can't contain whitespace.
   129  	MetricName *string `pulumi:"metricName"`
   130  	// The name or description of the rule.
   131  	Name *string `pulumi:"name"`
   132  	// The objects to include in a rule (documented below).
   133  	Predicates []RulePredicate `pulumi:"predicates"`
   134  	// 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.
   135  	Tags map[string]string `pulumi:"tags"`
   136  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   137  	//
   138  	// Deprecated: Please use `tags` instead.
   139  	TagsAll map[string]string `pulumi:"tagsAll"`
   140  }
   141  
   142  type RuleState struct {
   143  	// The ARN of the WAF rule.
   144  	Arn pulumi.StringPtrInput
   145  	// The name or description for the Amazon CloudWatch metric of this rule. The name can contain only alphanumeric characters (A-Z, a-z, 0-9); the name can't contain whitespace.
   146  	MetricName pulumi.StringPtrInput
   147  	// The name or description of the rule.
   148  	Name pulumi.StringPtrInput
   149  	// The objects to include in a rule (documented below).
   150  	Predicates RulePredicateArrayInput
   151  	// 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.
   152  	Tags pulumi.StringMapInput
   153  	// A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   154  	//
   155  	// Deprecated: Please use `tags` instead.
   156  	TagsAll pulumi.StringMapInput
   157  }
   158  
   159  func (RuleState) ElementType() reflect.Type {
   160  	return reflect.TypeOf((*ruleState)(nil)).Elem()
   161  }
   162  
   163  type ruleArgs struct {
   164  	// The name or description for the Amazon CloudWatch metric of this rule. The name can contain only alphanumeric characters (A-Z, a-z, 0-9); the name can't contain whitespace.
   165  	MetricName string `pulumi:"metricName"`
   166  	// The name or description of the rule.
   167  	Name *string `pulumi:"name"`
   168  	// The objects to include in a rule (documented below).
   169  	Predicates []RulePredicate `pulumi:"predicates"`
   170  	// 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.
   171  	Tags map[string]string `pulumi:"tags"`
   172  }
   173  
   174  // The set of arguments for constructing a Rule resource.
   175  type RuleArgs struct {
   176  	// The name or description for the Amazon CloudWatch metric of this rule. The name can contain only alphanumeric characters (A-Z, a-z, 0-9); the name can't contain whitespace.
   177  	MetricName pulumi.StringInput
   178  	// The name or description of the rule.
   179  	Name pulumi.StringPtrInput
   180  	// The objects to include in a rule (documented below).
   181  	Predicates RulePredicateArrayInput
   182  	// 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.
   183  	Tags pulumi.StringMapInput
   184  }
   185  
   186  func (RuleArgs) ElementType() reflect.Type {
   187  	return reflect.TypeOf((*ruleArgs)(nil)).Elem()
   188  }
   189  
   190  type RuleInput interface {
   191  	pulumi.Input
   192  
   193  	ToRuleOutput() RuleOutput
   194  	ToRuleOutputWithContext(ctx context.Context) RuleOutput
   195  }
   196  
   197  func (*Rule) ElementType() reflect.Type {
   198  	return reflect.TypeOf((**Rule)(nil)).Elem()
   199  }
   200  
   201  func (i *Rule) ToRuleOutput() RuleOutput {
   202  	return i.ToRuleOutputWithContext(context.Background())
   203  }
   204  
   205  func (i *Rule) ToRuleOutputWithContext(ctx context.Context) RuleOutput {
   206  	return pulumi.ToOutputWithContext(ctx, i).(RuleOutput)
   207  }
   208  
   209  // RuleArrayInput is an input type that accepts RuleArray and RuleArrayOutput values.
   210  // You can construct a concrete instance of `RuleArrayInput` via:
   211  //
   212  //	RuleArray{ RuleArgs{...} }
   213  type RuleArrayInput interface {
   214  	pulumi.Input
   215  
   216  	ToRuleArrayOutput() RuleArrayOutput
   217  	ToRuleArrayOutputWithContext(context.Context) RuleArrayOutput
   218  }
   219  
   220  type RuleArray []RuleInput
   221  
   222  func (RuleArray) ElementType() reflect.Type {
   223  	return reflect.TypeOf((*[]*Rule)(nil)).Elem()
   224  }
   225  
   226  func (i RuleArray) ToRuleArrayOutput() RuleArrayOutput {
   227  	return i.ToRuleArrayOutputWithContext(context.Background())
   228  }
   229  
   230  func (i RuleArray) ToRuleArrayOutputWithContext(ctx context.Context) RuleArrayOutput {
   231  	return pulumi.ToOutputWithContext(ctx, i).(RuleArrayOutput)
   232  }
   233  
   234  // RuleMapInput is an input type that accepts RuleMap and RuleMapOutput values.
   235  // You can construct a concrete instance of `RuleMapInput` via:
   236  //
   237  //	RuleMap{ "key": RuleArgs{...} }
   238  type RuleMapInput interface {
   239  	pulumi.Input
   240  
   241  	ToRuleMapOutput() RuleMapOutput
   242  	ToRuleMapOutputWithContext(context.Context) RuleMapOutput
   243  }
   244  
   245  type RuleMap map[string]RuleInput
   246  
   247  func (RuleMap) ElementType() reflect.Type {
   248  	return reflect.TypeOf((*map[string]*Rule)(nil)).Elem()
   249  }
   250  
   251  func (i RuleMap) ToRuleMapOutput() RuleMapOutput {
   252  	return i.ToRuleMapOutputWithContext(context.Background())
   253  }
   254  
   255  func (i RuleMap) ToRuleMapOutputWithContext(ctx context.Context) RuleMapOutput {
   256  	return pulumi.ToOutputWithContext(ctx, i).(RuleMapOutput)
   257  }
   258  
   259  type RuleOutput struct{ *pulumi.OutputState }
   260  
   261  func (RuleOutput) ElementType() reflect.Type {
   262  	return reflect.TypeOf((**Rule)(nil)).Elem()
   263  }
   264  
   265  func (o RuleOutput) ToRuleOutput() RuleOutput {
   266  	return o
   267  }
   268  
   269  func (o RuleOutput) ToRuleOutputWithContext(ctx context.Context) RuleOutput {
   270  	return o
   271  }
   272  
   273  // The ARN of the WAF rule.
   274  func (o RuleOutput) Arn() pulumi.StringOutput {
   275  	return o.ApplyT(func(v *Rule) pulumi.StringOutput { return v.Arn }).(pulumi.StringOutput)
   276  }
   277  
   278  // The name or description for the Amazon CloudWatch metric of this rule. The name can contain only alphanumeric characters (A-Z, a-z, 0-9); the name can't contain whitespace.
   279  func (o RuleOutput) MetricName() pulumi.StringOutput {
   280  	return o.ApplyT(func(v *Rule) pulumi.StringOutput { return v.MetricName }).(pulumi.StringOutput)
   281  }
   282  
   283  // The name or description of the rule.
   284  func (o RuleOutput) Name() pulumi.StringOutput {
   285  	return o.ApplyT(func(v *Rule) pulumi.StringOutput { return v.Name }).(pulumi.StringOutput)
   286  }
   287  
   288  // The objects to include in a rule (documented below).
   289  func (o RuleOutput) Predicates() RulePredicateArrayOutput {
   290  	return o.ApplyT(func(v *Rule) RulePredicateArrayOutput { return v.Predicates }).(RulePredicateArrayOutput)
   291  }
   292  
   293  // 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.
   294  func (o RuleOutput) Tags() pulumi.StringMapOutput {
   295  	return o.ApplyT(func(v *Rule) pulumi.StringMapOutput { return v.Tags }).(pulumi.StringMapOutput)
   296  }
   297  
   298  // A map of tags assigned to the resource, including those inherited from the provider `defaultTags` configuration block.
   299  //
   300  // Deprecated: Please use `tags` instead.
   301  func (o RuleOutput) TagsAll() pulumi.StringMapOutput {
   302  	return o.ApplyT(func(v *Rule) pulumi.StringMapOutput { return v.TagsAll }).(pulumi.StringMapOutput)
   303  }
   304  
   305  type RuleArrayOutput struct{ *pulumi.OutputState }
   306  
   307  func (RuleArrayOutput) ElementType() reflect.Type {
   308  	return reflect.TypeOf((*[]*Rule)(nil)).Elem()
   309  }
   310  
   311  func (o RuleArrayOutput) ToRuleArrayOutput() RuleArrayOutput {
   312  	return o
   313  }
   314  
   315  func (o RuleArrayOutput) ToRuleArrayOutputWithContext(ctx context.Context) RuleArrayOutput {
   316  	return o
   317  }
   318  
   319  func (o RuleArrayOutput) Index(i pulumi.IntInput) RuleOutput {
   320  	return pulumi.All(o, i).ApplyT(func(vs []interface{}) *Rule {
   321  		return vs[0].([]*Rule)[vs[1].(int)]
   322  	}).(RuleOutput)
   323  }
   324  
   325  type RuleMapOutput struct{ *pulumi.OutputState }
   326  
   327  func (RuleMapOutput) ElementType() reflect.Type {
   328  	return reflect.TypeOf((*map[string]*Rule)(nil)).Elem()
   329  }
   330  
   331  func (o RuleMapOutput) ToRuleMapOutput() RuleMapOutput {
   332  	return o
   333  }
   334  
   335  func (o RuleMapOutput) ToRuleMapOutputWithContext(ctx context.Context) RuleMapOutput {
   336  	return o
   337  }
   338  
   339  func (o RuleMapOutput) MapIndex(k pulumi.StringInput) RuleOutput {
   340  	return pulumi.All(o, k).ApplyT(func(vs []interface{}) *Rule {
   341  		return vs[0].(map[string]*Rule)[vs[1].(string)]
   342  	}).(RuleOutput)
   343  }
   344  
   345  func init() {
   346  	pulumi.RegisterInputType(reflect.TypeOf((*RuleInput)(nil)).Elem(), &Rule{})
   347  	pulumi.RegisterInputType(reflect.TypeOf((*RuleArrayInput)(nil)).Elem(), RuleArray{})
   348  	pulumi.RegisterInputType(reflect.TypeOf((*RuleMapInput)(nil)).Elem(), RuleMap{})
   349  	pulumi.RegisterOutputType(RuleOutput{})
   350  	pulumi.RegisterOutputType(RuleArrayOutput{})
   351  	pulumi.RegisterOutputType(RuleMapOutput{})
   352  }