github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_config_config_rule_invalid_maximum_execution_frequency.go (about)

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