github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_directory_service_directory_invalid_name.go (about) 1 // This file generated by `generator/`. DO NOT EDIT 2 3 package models 4 5 import ( 6 "fmt" 7 "log" 8 "regexp" 9 10 hcl "github.com/hashicorp/hcl/v2" 11 "github.com/terraform-linters/tflint/tflint" 12 ) 13 14 // AwsDirectoryServiceDirectoryInvalidNameRule checks the pattern is valid 15 type AwsDirectoryServiceDirectoryInvalidNameRule struct { 16 resourceType string 17 attributeName string 18 pattern *regexp.Regexp 19 } 20 21 // NewAwsDirectoryServiceDirectoryInvalidNameRule returns new rule with default attributes 22 func NewAwsDirectoryServiceDirectoryInvalidNameRule() *AwsDirectoryServiceDirectoryInvalidNameRule { 23 return &AwsDirectoryServiceDirectoryInvalidNameRule{ 24 resourceType: "aws_directory_service_directory", 25 attributeName: "name", 26 pattern: regexp.MustCompile(`^([a-zA-Z0-9]+[\\.-])+([a-zA-Z0-9])+$`), 27 } 28 } 29 30 // Name returns the rule name 31 func (r *AwsDirectoryServiceDirectoryInvalidNameRule) Name() string { 32 return "aws_directory_service_directory_invalid_name" 33 } 34 35 // Enabled returns whether the rule is enabled by default 36 func (r *AwsDirectoryServiceDirectoryInvalidNameRule) Enabled() bool { 37 return true 38 } 39 40 // Severity returns the rule severity 41 func (r *AwsDirectoryServiceDirectoryInvalidNameRule) Severity() string { 42 return tflint.ERROR 43 } 44 45 // Link returns the rule reference link 46 func (r *AwsDirectoryServiceDirectoryInvalidNameRule) Link() string { 47 return "" 48 } 49 50 // Check checks the pattern is valid 51 func (r *AwsDirectoryServiceDirectoryInvalidNameRule) Check(runner *tflint.Runner) error { 52 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 53 54 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 55 var val string 56 err := runner.EvaluateExpr(attribute.Expr, &val) 57 58 return runner.EnsureNoError(err, func() error { 59 if !r.pattern.MatchString(val) { 60 runner.EmitIssue( 61 r, 62 fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^([a-zA-Z0-9]+[\\.-])+([a-zA-Z0-9])+$`), 63 attribute.Expr.Range(), 64 ) 65 } 66 return nil 67 }) 68 }) 69 }