github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_elasticache_cluster_invalid_az_mode.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 // AwsElastiCacheClusterInvalidAzModeRule checks the pattern is valid 13 type AwsElastiCacheClusterInvalidAzModeRule struct { 14 resourceType string 15 attributeName string 16 enum []string 17 } 18 19 // NewAwsElastiCacheClusterInvalidAzModeRule returns new rule with default attributes 20 func NewAwsElastiCacheClusterInvalidAzModeRule() *AwsElastiCacheClusterInvalidAzModeRule { 21 return &AwsElastiCacheClusterInvalidAzModeRule{ 22 resourceType: "aws_elasticache_cluster", 23 attributeName: "az_mode", 24 enum: []string{ 25 "single-az", 26 "cross-az", 27 }, 28 } 29 } 30 31 // Name returns the rule name 32 func (r *AwsElastiCacheClusterInvalidAzModeRule) Name() string { 33 return "aws_elasticache_cluster_invalid_az_mode" 34 } 35 36 // Enabled returns whether the rule is enabled by default 37 func (r *AwsElastiCacheClusterInvalidAzModeRule) Enabled() bool { 38 return true 39 } 40 41 // Severity returns the rule severity 42 func (r *AwsElastiCacheClusterInvalidAzModeRule) Severity() string { 43 return tflint.ERROR 44 } 45 46 // Link returns the rule reference link 47 func (r *AwsElastiCacheClusterInvalidAzModeRule) Link() string { 48 return "" 49 } 50 51 // Check checks the pattern is valid 52 func (r *AwsElastiCacheClusterInvalidAzModeRule) 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 `az_mode is not a valid value`, 70 attribute.Expr.Range(), 71 ) 72 } 73 return nil 74 }) 75 }) 76 }