github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_config_config_rule_invalid_maximum_execution_frequency.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  // AwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule checks the pattern is valid
    14  type AwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule struct {
    15  	resourceType  string
    16  	attributeName string
    17  	enum          []string
    18  }
    19  
    20  // NewAwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule returns new rule with default attributes
    21  func NewAwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule() *AwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule {
    22  	return &AwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule{
    23  		resourceType:  "aws_config_config_rule",
    24  		attributeName: "maximum_execution_frequency",
    25  		enum: []string{
    26  			"One_Hour",
    27  			"Three_Hours",
    28  			"Six_Hours",
    29  			"Twelve_Hours",
    30  			"TwentyFour_Hours",
    31  		},
    32  	}
    33  }
    34  
    35  // Name returns the rule name
    36  func (r *AwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule) Name() string {
    37  	return "aws_config_config_rule_invalid_maximum_execution_frequency"
    38  }
    39  
    40  // Enabled returns whether the rule is enabled by default
    41  func (r *AwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule) Enabled() bool {
    42  	return true
    43  }
    44  
    45  // Severity returns the rule severity
    46  func (r *AwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule) Severity() string {
    47  	return tflint.ERROR
    48  }
    49  
    50  // Link returns the rule reference link
    51  func (r *AwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule) Link() string {
    52  	return ""
    53  }
    54  
    55  // Check checks the pattern is valid
    56  func (r *AwsConfigConfigRuleInvalidMaximumExecutionFrequencyRule) Check(runner *tflint.Runner) error {
    57  	log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath())
    58  
    59  	return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error {
    60  		var val string
    61  		err := runner.EvaluateExpr(attribute.Expr, &val)
    62  
    63  		return runner.EnsureNoError(err, func() error {
    64  			found := false
    65  			for _, item := range r.enum {
    66  				if item == val {
    67  					found = true
    68  				}
    69  			}
    70  			if !found {
    71  				runner.EmitIssue(
    72  					r,
    73  					fmt.Sprintf(`"%s" is an invalid value as maximum_execution_frequency`, truncateLongMessage(val)),
    74  					attribute.Expr.Range(),
    75  				)
    76  			}
    77  			return nil
    78  		})
    79  	})
    80  }