github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_waf_rate_based_rule_invalid_rate_key.go (about)

     1  // This file generated by `generator/`. DO NOT EDIT
     2  
     3  package models
     4  
     5  import (
     6  	"fmt"
     7  	"log"
     8  
     9  	hcl "github.com/hashicorp/hcl/v2"
    10  	"github.com/terraform-linters/tflint/tflint"
    11  )
    12  
    13  // AwsWafRateBasedRuleInvalidRateKeyRule checks the pattern is valid
    14  type AwsWafRateBasedRuleInvalidRateKeyRule struct {
    15  	resourceType  string
    16  	attributeName string
    17  	enum          []string
    18  }
    19  
    20  // NewAwsWafRateBasedRuleInvalidRateKeyRule returns new rule with default attributes
    21  func NewAwsWafRateBasedRuleInvalidRateKeyRule() *AwsWafRateBasedRuleInvalidRateKeyRule {
    22  	return &AwsWafRateBasedRuleInvalidRateKeyRule{
    23  		resourceType:  "aws_waf_rate_based_rule",
    24  		attributeName: "rate_key",
    25  		enum: []string{
    26  			"IP",
    27  		},
    28  	}
    29  }
    30  
    31  // Name returns the rule name
    32  func (r *AwsWafRateBasedRuleInvalidRateKeyRule) Name() string {
    33  	return "aws_waf_rate_based_rule_invalid_rate_key"
    34  }
    35  
    36  // Enabled returns whether the rule is enabled by default
    37  func (r *AwsWafRateBasedRuleInvalidRateKeyRule) Enabled() bool {
    38  	return true
    39  }
    40  
    41  // Severity returns the rule severity
    42  func (r *AwsWafRateBasedRuleInvalidRateKeyRule) Severity() string {
    43  	return tflint.ERROR
    44  }
    45  
    46  // Link returns the rule reference link
    47  func (r *AwsWafRateBasedRuleInvalidRateKeyRule) Link() string {
    48  	return ""
    49  }
    50  
    51  // Check checks the pattern is valid
    52  func (r *AwsWafRateBasedRuleInvalidRateKeyRule) Check(runner *tflint.Runner) error {
    53  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    54  
    55  	return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
    56  		var val string
    57  		err := runner.EvaluateExpr(attribute.Expr, &val)
    58  
    59  		return runner.EnsureNoError(err, func() error {
    60  			found := false
    61  			for _, item := range r.enum {
    62  				if item == val {
    63  					found = true
    64  				}
    65  			}
    66  			if !found {
    67  				runner.EmitIssue(
    68  					r,
    69  					fmt.Sprintf(`"%s" is an invalid value as rate_key`, truncateLongMessage(val)),
    70  					attribute.Expr.Range(),
    71  				)
    72  			}
    73  			return nil
    74  		})
    75  	})
    76  }