github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_cloudhsm_v2_hsm_invalid_availability_zone.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 "regexp" 8 9 hcl "github.com/hashicorp/hcl/v2" 10 "github.com/wata727/tflint/tflint" 11 ) 12 13 // AwsCloudhsmV2HsmInvalidAvailabilityZoneRule checks the pattern is valid 14 type AwsCloudhsmV2HsmInvalidAvailabilityZoneRule struct { 15 resourceType string 16 attributeName string 17 pattern *regexp.Regexp 18 } 19 20 // NewAwsCloudhsmV2HsmInvalidAvailabilityZoneRule returns new rule with default attributes 21 func NewAwsCloudhsmV2HsmInvalidAvailabilityZoneRule() *AwsCloudhsmV2HsmInvalidAvailabilityZoneRule { 22 return &AwsCloudhsmV2HsmInvalidAvailabilityZoneRule{ 23 resourceType: "aws_cloudhsm_v2_hsm", 24 attributeName: "availability_zone", 25 pattern: regexp.MustCompile(`^[a-z]{2}(-(gov))?-(east|west|north|south|central){1,2}-\d[a-z]$`), 26 } 27 } 28 29 // Name returns the rule name 30 func (r *AwsCloudhsmV2HsmInvalidAvailabilityZoneRule) Name() string { 31 return "aws_cloudhsm_v2_hsm_invalid_availability_zone" 32 } 33 34 // Enabled returns whether the rule is enabled by default 35 func (r *AwsCloudhsmV2HsmInvalidAvailabilityZoneRule) Enabled() bool { 36 return true 37 } 38 39 // Severity returns the rule severity 40 func (r *AwsCloudhsmV2HsmInvalidAvailabilityZoneRule) Severity() string { 41 return tflint.ERROR 42 } 43 44 // Link returns the rule reference link 45 func (r *AwsCloudhsmV2HsmInvalidAvailabilityZoneRule) Link() string { 46 return "" 47 } 48 49 // Check checks the pattern is valid 50 func (r *AwsCloudhsmV2HsmInvalidAvailabilityZoneRule) Check(runner *tflint.Runner) error { 51 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 52 53 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 54 var val string 55 err := runner.EvaluateExpr(attribute.Expr, &val) 56 57 return runner.EnsureNoError(err, func() error { 58 if !r.pattern.MatchString(val) { 59 runner.EmitIssue( 60 r, 61 `availability_zone does not match valid pattern ^[a-z]{2}(-(gov))?-(east|west|north|south|central){1,2}-\d[a-z]$`, 62 attribute.Expr.Range(), 63 ) 64 } 65 return nil 66 }) 67 }) 68 }