github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_transfer_ssh_key_invalid_server_id.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 // AwsTransferSSHKeyInvalidServerIDRule checks the pattern is valid 14 type AwsTransferSSHKeyInvalidServerIDRule struct { 15 resourceType string 16 attributeName string 17 pattern *regexp.Regexp 18 } 19 20 // NewAwsTransferSSHKeyInvalidServerIDRule returns new rule with default attributes 21 func NewAwsTransferSSHKeyInvalidServerIDRule() *AwsTransferSSHKeyInvalidServerIDRule { 22 return &AwsTransferSSHKeyInvalidServerIDRule{ 23 resourceType: "aws_transfer_ssh_key", 24 attributeName: "server_id", 25 pattern: regexp.MustCompile(`^s-([0-9a-f]{17})$`), 26 } 27 } 28 29 // Name returns the rule name 30 func (r *AwsTransferSSHKeyInvalidServerIDRule) Name() string { 31 return "aws_transfer_ssh_key_invalid_server_id" 32 } 33 34 // Enabled returns whether the rule is enabled by default 35 func (r *AwsTransferSSHKeyInvalidServerIDRule) Enabled() bool { 36 return true 37 } 38 39 // Severity returns the rule severity 40 func (r *AwsTransferSSHKeyInvalidServerIDRule) Severity() string { 41 return tflint.ERROR 42 } 43 44 // Link returns the rule reference link 45 func (r *AwsTransferSSHKeyInvalidServerIDRule) Link() string { 46 return "" 47 } 48 49 // Check checks the pattern is valid 50 func (r *AwsTransferSSHKeyInvalidServerIDRule) 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 `server_id does not match valid pattern ^s-([0-9a-f]{17})$`, 62 attribute.Expr.Range(), 63 ) 64 } 65 return nil 66 }) 67 }) 68 }