github.com/wata727/tflint@v0.12.2-0.20191013070026-96dd0d36f385/rules/awsrules/models/aws_sagemaker_endpoint_invalid_endpoint_config_name.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 // AwsSagemakerEndpointInvalidEndpointConfigNameRule checks the pattern is valid 14 type AwsSagemakerEndpointInvalidEndpointConfigNameRule struct { 15 resourceType string 16 attributeName string 17 max int 18 pattern *regexp.Regexp 19 } 20 21 // NewAwsSagemakerEndpointInvalidEndpointConfigNameRule returns new rule with default attributes 22 func NewAwsSagemakerEndpointInvalidEndpointConfigNameRule() *AwsSagemakerEndpointInvalidEndpointConfigNameRule { 23 return &AwsSagemakerEndpointInvalidEndpointConfigNameRule{ 24 resourceType: "aws_sagemaker_endpoint", 25 attributeName: "endpoint_config_name", 26 max: 63, 27 pattern: regexp.MustCompile(`^[a-zA-Z0-9](-*[a-zA-Z0-9])*`), 28 } 29 } 30 31 // Name returns the rule name 32 func (r *AwsSagemakerEndpointInvalidEndpointConfigNameRule) Name() string { 33 return "aws_sagemaker_endpoint_invalid_endpoint_config_name" 34 } 35 36 // Enabled returns whether the rule is enabled by default 37 func (r *AwsSagemakerEndpointInvalidEndpointConfigNameRule) Enabled() bool { 38 return true 39 } 40 41 // Severity returns the rule severity 42 func (r *AwsSagemakerEndpointInvalidEndpointConfigNameRule) Severity() string { 43 return tflint.ERROR 44 } 45 46 // Link returns the rule reference link 47 func (r *AwsSagemakerEndpointInvalidEndpointConfigNameRule) Link() string { 48 return "" 49 } 50 51 // Check checks the pattern is valid 52 func (r *AwsSagemakerEndpointInvalidEndpointConfigNameRule) 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 if len(val) > r.max { 61 runner.EmitIssue( 62 r, 63 "endpoint_config_name must be 63 characters or less", 64 attribute.Expr.Range(), 65 ) 66 } 67 if !r.pattern.MatchString(val) { 68 runner.EmitIssue( 69 r, 70 `endpoint_config_name does not match valid pattern ^[a-zA-Z0-9](-*[a-zA-Z0-9])*`, 71 attribute.Expr.Range(), 72 ) 73 } 74 return nil 75 }) 76 }) 77 }