github.com/jpreese/tflint@v0.19.2-0.20200908152133-b01686250fb6/rules/awsrules/models/aws_sagemaker_model_invalid_execution_role_arn.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 // AwsSagemakerModelInvalidExecutionRoleArnRule checks the pattern is valid 15 type AwsSagemakerModelInvalidExecutionRoleArnRule struct { 16 resourceType string 17 attributeName string 18 max int 19 min int 20 pattern *regexp.Regexp 21 } 22 23 // NewAwsSagemakerModelInvalidExecutionRoleArnRule returns new rule with default attributes 24 func NewAwsSagemakerModelInvalidExecutionRoleArnRule() *AwsSagemakerModelInvalidExecutionRoleArnRule { 25 return &AwsSagemakerModelInvalidExecutionRoleArnRule{ 26 resourceType: "aws_sagemaker_model", 27 attributeName: "execution_role_arn", 28 max: 2048, 29 min: 20, 30 pattern: regexp.MustCompile(`^arn:aws[a-z\-]*:iam::\d{12}:role/?[a-zA-Z_0-9+=,.@\-_/]+$`), 31 } 32 } 33 34 // Name returns the rule name 35 func (r *AwsSagemakerModelInvalidExecutionRoleArnRule) Name() string { 36 return "aws_sagemaker_model_invalid_execution_role_arn" 37 } 38 39 // Enabled returns whether the rule is enabled by default 40 func (r *AwsSagemakerModelInvalidExecutionRoleArnRule) Enabled() bool { 41 return true 42 } 43 44 // Severity returns the rule severity 45 func (r *AwsSagemakerModelInvalidExecutionRoleArnRule) Severity() string { 46 return tflint.ERROR 47 } 48 49 // Link returns the rule reference link 50 func (r *AwsSagemakerModelInvalidExecutionRoleArnRule) Link() string { 51 return "" 52 } 53 54 // Check checks the pattern is valid 55 func (r *AwsSagemakerModelInvalidExecutionRoleArnRule) Check(runner *tflint.Runner) error { 56 log.Printf("[TRACE] Check `%s` rule for `%s` runner", r.Name(), runner.TFConfigPath()) 57 58 return runner.WalkResourceAttributes(r.resourceType, r.attributeName, func(attribute *hcl.Attribute) error { 59 var val string 60 err := runner.EvaluateExpr(attribute.Expr, &val) 61 62 return runner.EnsureNoError(err, func() error { 63 if len(val) > r.max { 64 runner.EmitIssue( 65 r, 66 "execution_role_arn must be 2048 characters or less", 67 attribute.Expr.Range(), 68 ) 69 } 70 if len(val) < r.min { 71 runner.EmitIssue( 72 r, 73 "execution_role_arn must be 20 characters or higher", 74 attribute.Expr.Range(), 75 ) 76 } 77 if !r.pattern.MatchString(val) { 78 runner.EmitIssue( 79 r, 80 fmt.Sprintf(`"%s" does not match valid pattern %s`, truncateLongMessage(val), `^arn:aws[a-z\-]*:iam::\d{12}:role/?[a-zA-Z_0-9+=,.@\-_/]+$`), 81 attribute.Expr.Range(), 82 ) 83 } 84 return nil 85 }) 86 }) 87 }