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