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